@cendor/guardrails 0.1.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -3
- package/dist/.tsbuildinfo +1 -1
- package/dist/adapters.d.ts +150 -0
- package/dist/adapters.d.ts.map +1 -0
- package/dist/adapters.js +414 -0
- package/dist/adapters.js.map +1 -0
- package/dist/decision.d.ts +62 -2
- package/dist/decision.d.ts.map +1 -1
- package/dist/decision.js +44 -3
- package/dist/decision.js.map +1 -1
- package/dist/index.d.ts +38 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +231 -40
- package/dist/index.js.map +1 -1
- package/dist/judge.d.ts +91 -0
- package/dist/judge.d.ts.map +1 -0
- package/dist/judge.js +171 -0
- package/dist/judge.js.map +1 -0
- package/dist/policy.d.ts +41 -0
- package/dist/policy.d.ts.map +1 -0
- package/dist/policy.js +209 -0
- package/dist/policy.js.map +1 -0
- package/dist/redteam.d.ts +63 -0
- package/dist/redteam.d.ts.map +1 -0
- package/dist/redteam.js +154 -0
- package/dist/redteam.js.map +1 -0
- package/dist/rules.d.ts +39 -3
- package/dist/rules.d.ts.map +1 -1
- package/dist/rules.js +97 -6
- package/dist/rules.js.map +1 -1
- package/dist/semantic.d.ts +52 -0
- package/dist/semantic.d.ts.map +1 -0
- package/dist/semantic.js +100 -0
- package/dist/semantic.js.map +1 -0
- package/package.json +1 -1
package/dist/decision.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"decision.js","sourceRoot":"","sources":["../src/decision.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,yDAAyD;AACzD,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,QAAQ,CAAU,CAAC;AAG/E,wEAAwE;AACxE,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,OAAO,EAAE,QAAQ,EAAE,MAAM,CAAU,CAAC;A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Decision } from './decision.js';
|
|
15
|
-
export { STAGES, ACTIONS, Verdict, GuardrailDecision, GuardrailTripped, defineGuardrail, normalizeStages, } from './decision.js';
|
|
16
|
-
export type { Stage, Action, Context, Check, Guardrail, DefineGuardrailOptions, } from './decision.js';
|
|
15
|
+
export { STAGES, ACTIONS, ON_ERROR, Verdict, GuardrailDecision, GuardrailTripped, defineGuardrail, normalizeStages, validateExecutionPolicy, } from './decision.js';
|
|
16
|
+
export type { Stage, Action, OnError, Context, Check, Guardrail, DefineGuardrailOptions, } from './decision.js';
|
|
17
17
|
export * as rules from './rules.js';
|
|
18
|
+
export * as judge from './judge.js';
|
|
19
|
+
export * as adapters from './adapters.js';
|
|
20
|
+
export * as semantic from './semantic.js';
|
|
21
|
+
export * as redteam from './redteam.js';
|
|
22
|
+
export { loadPolicy, POLICY_RULE_NAMES } from './policy.js';
|
|
23
|
+
export type { LoadedPolicy, LoadPolicyOptions } from './policy.js';
|
|
24
|
+
export type { Embed } from './semantic.js';
|
|
25
|
+
export { loadCorpus, runRedteam, runRedteamAsync, RedTeamReport } from './redteam.js';
|
|
26
|
+
export type { AttackCase, LoadCorpusOptions } from './redteam.js';
|
|
18
27
|
/** The result of evaluating a stage: the (possibly redacted) payload plus the recorded decisions. */
|
|
19
28
|
export interface EvalResult {
|
|
20
29
|
payload: unknown;
|
|
@@ -23,10 +32,15 @@ export interface EvalResult {
|
|
|
23
32
|
/**
|
|
24
33
|
* Run the `stage` guardrails over `payload` **synchronously**. Returns `{ payload, decisions }`
|
|
25
34
|
* with any redactions applied in order; throws `GuardrailTripped` on the first block. An `async`
|
|
26
|
-
* check throws here — use {@link evaluateAsync}.
|
|
35
|
+
* check throws here — use {@link evaluateAsync}. A *throwing* sync check honours its `onError`
|
|
36
|
+
* policy; `timeout` applies to the async path only (no sync threads in JS).
|
|
27
37
|
*/
|
|
28
38
|
export declare function evaluate(guardrails: readonly Guardrail[], stage: string, payload: unknown, ctx?: Context): EvalResult;
|
|
29
|
-
/**
|
|
39
|
+
/**
|
|
40
|
+
* Async counterpart of {@link evaluate}: awaits `async` checks (bounded by each guardrail's
|
|
41
|
+
* `timeout`), calls sync ones directly, and applies each guardrail's `onError` policy on a
|
|
42
|
+
* throw/timeout.
|
|
43
|
+
*/
|
|
30
44
|
export declare function evaluateAsync(guardrails: readonly Guardrail[], stage: string, payload: unknown, ctx?: Context): Promise<EvalResult>;
|
|
31
45
|
/** Gate `payload` and return the recorded decisions (throws `GuardrailTripped` on a block). */
|
|
32
46
|
export declare function apply(guardrails: readonly Guardrail[], stage: string, payload: unknown, ctx?: Context): GuardrailDecision[];
|
|
@@ -38,11 +52,30 @@ export declare function applyAsync(guardrails: readonly Guardrail[], stage: stri
|
|
|
38
52
|
* cleaned messages, a pass declines. tool_call: a block raises; else record + proceed (tools have
|
|
39
53
|
* no message-rewrite seam). Output: a bus subscriber raises **post-flight** on a block (same
|
|
40
54
|
* overshoot semantics as tokenguard's `onExceed:"raise"`). Runs sync checks only. Call
|
|
41
|
-
* {@link uninstall} to remove.
|
|
55
|
+
* {@link uninstall} to remove. `install()` is **process-global** — for a concurrent server that
|
|
56
|
+
* varies guardrails per request, use {@link scoped} instead.
|
|
42
57
|
*/
|
|
43
58
|
export declare function install(guardrails: readonly Guardrail[]): void;
|
|
44
59
|
/** Remove the interceptor + output subscriber registered by {@link install} (idempotent). */
|
|
45
60
|
export declare function uninstall(): void;
|
|
61
|
+
/**
|
|
62
|
+
* Gate every instrumented call for the duration of `fn` — like {@link install}, but **scoped to the
|
|
63
|
+
* current execution context** rather than process-global. Runs `fn` with `guardrails` active and
|
|
64
|
+
* returns its result (sync or a `Promise`); the previous scope is restored on exit.
|
|
65
|
+
*
|
|
66
|
+
* With a real `AsyncLocalStorage` (auto-installed on Node), a concurrent server (async tasks) can
|
|
67
|
+
* vary guardrails per request without one request's set leaking into another. On edge/browser the
|
|
68
|
+
* fallback is a save/restore module variable — correct for sequential/nested use, **not**
|
|
69
|
+
* concurrency-safe. Nest freely — an inner `scoped` replaces the set for its block. Runs sync checks
|
|
70
|
+
* only (the seam is sync).
|
|
71
|
+
*
|
|
72
|
+
* ```ts
|
|
73
|
+
* await scoped([rules.keywordDeny(['secret'], { action: 'block' })], async () => {
|
|
74
|
+
* await client.chat.completions.create(...); // gated here
|
|
75
|
+
* });
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
export declare function scoped<T>(guardrails: readonly Guardrail[], fn: () => T | Promise<T>): T | Promise<T>;
|
|
46
79
|
/** Best-effort assistant text off a completed LLMCall for the standalone output stage. */
|
|
47
80
|
export declare function responseText(call: LLMCall): string | null;
|
|
48
81
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EACL,OAAO,EAQR,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,SAAS,EACd,iBAAiB,EAGlB,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,MAAM,EACN,OAAO,EACP,OAAO,EACP,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EACf,eAAe,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EACL,OAAO,EAQR,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,SAAS,EACd,iBAAiB,EAGlB,MAAM,eAAe,CAAC;AAEvB,OAAO,EACL,MAAM,EACN,OAAO,EACP,QAAQ,EACR,OAAO,EACP,iBAAiB,EACjB,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,uBAAuB,GACxB,MAAM,eAAe,CAAC;AACvB,YAAY,EACV,KAAK,EACL,MAAM,EACN,OAAO,EACP,OAAO,EACP,KAAK,EACL,SA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A0C;AAC1C,wBAAsB,UAAU,CAC9B,UAAU,EAAE,SAAS,SAAS,EAAE,EAChC,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,OAAO,EAChB,GAAG,CAAC,EAAE,OAAO,GACZ,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAE9B;AA4CD;;;;;;;;GAQG;AACH,wBAAgB,OAAO,CAAC,UAAU,EAAE,SAAS,SAAS,EAAE,GAAG,IAAI,CAS9D;AAED,6FAA6F;AAC7F,wBAAgB,SAAS,IAAI,IAAI,CAKhC;AA6DD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,MAAM,CAAC,CAAC,EACtB,UAAU,EAAE,SAAS,SAAS,EAAE,EAChC,EAAE,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,GACvB,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAsBhB;AAQD,0FAA0F;AAC1F,wBAAgB,YAAY,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAQzD"}
|
package/dist/index.js
CHANGED
|
@@ -11,9 +11,15 @@
|
|
|
11
11
|
* Imports ONLY `@cendor/core` (constitution rule 2). See docs/guardrails.md.
|
|
12
12
|
*/
|
|
13
13
|
import { LLMCall, MISS, Reroute, ToolCall, addInterceptor, bus, currentTraceId, removeInterceptor, } from '@cendor/core';
|
|
14
|
-
import { GuardrailDecision, GuardrailTripped, } from './decision.js';
|
|
15
|
-
export { STAGES, ACTIONS, Verdict, GuardrailDecision, GuardrailTripped, defineGuardrail, normalizeStages, } from './decision.js';
|
|
14
|
+
import { GuardrailDecision, GuardrailTripped, Verdict, } from './decision.js';
|
|
15
|
+
export { STAGES, ACTIONS, ON_ERROR, Verdict, GuardrailDecision, GuardrailTripped, defineGuardrail, normalizeStages, validateExecutionPolicy, } from './decision.js';
|
|
16
16
|
export * as rules from './rules.js';
|
|
17
|
+
export * as judge from './judge.js';
|
|
18
|
+
export * as adapters from './adapters.js';
|
|
19
|
+
export * as semantic from './semantic.js';
|
|
20
|
+
export * as redteam from './redteam.js';
|
|
21
|
+
export { loadPolicy, POLICY_RULE_NAMES } from './policy.js';
|
|
22
|
+
export { loadCorpus, runRedteam, runRedteamAsync, RedTeamReport } from './redteam.js';
|
|
17
23
|
function applicable(guardrails, stage) {
|
|
18
24
|
return guardrails.filter((g) => g.stages.includes(stage));
|
|
19
25
|
}
|
|
@@ -27,7 +33,11 @@ function emit(g, stage, verdict, ctx) {
|
|
|
27
33
|
tool: ctx.tool ?? '',
|
|
28
34
|
traceId: ctx.traceId || currentTraceId(),
|
|
29
35
|
ts: new Date(),
|
|
30
|
-
metadata:
|
|
36
|
+
// Three metadata layers, lowest precedence first: the guardrail's static metadata (e.g.
|
|
37
|
+
// loadPolicy's policy_hash/version) is the base; the verdict's per-result annotations (the
|
|
38
|
+
// reserved severity/detected/… keys — see bus-events.md) layer over it; the caller's per-call
|
|
39
|
+
// Context.metadata is on top and still wins any key clash.
|
|
40
|
+
metadata: { ...(g.metadata ?? {}), ...(verdict.metadata ?? {}), ...(ctx.metadata ?? {}) },
|
|
31
41
|
});
|
|
32
42
|
bus.emit(decision); // acttrace (if attached) chains this as a guardrail_decision entry
|
|
33
43
|
return decision;
|
|
@@ -45,32 +55,109 @@ function handle(verdict, g, stage, payload, ctx, decisions) {
|
|
|
45
55
|
function isPromise(x) {
|
|
46
56
|
return x != null && typeof x.then === 'function';
|
|
47
57
|
}
|
|
58
|
+
const ERROR_REASON_MAX = 200;
|
|
59
|
+
/** A timeout marker error — a check that outran its `timeout` on the async path. */
|
|
60
|
+
class GuardrailTimeoutError extends Error {
|
|
61
|
+
constructor(message) {
|
|
62
|
+
super(message);
|
|
63
|
+
this.name = 'TimeoutError';
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Map a check error/timeout to a verdict per `g.onError`. Either way this becomes a
|
|
68
|
+
* `GuardrailDecision`, so the audit chain records that the check could not run — never a silently
|
|
69
|
+
* swallowed exception. The reason carries the error *name* + a truncated message, never the payload
|
|
70
|
+
* the check saw.
|
|
71
|
+
*/
|
|
72
|
+
function onErrorVerdict(g, exc) {
|
|
73
|
+
const name = exc?.name ??
|
|
74
|
+
exc?.constructor?.name ??
|
|
75
|
+
'Error';
|
|
76
|
+
const message = exc?.message ?? String(exc);
|
|
77
|
+
let detail = `${name}: ${message}`;
|
|
78
|
+
if (detail.length > ERROR_REASON_MAX)
|
|
79
|
+
detail = `${detail.slice(0, ERROR_REASON_MAX)}…`;
|
|
80
|
+
if ((g.onError ?? 'fail_closed') === 'fail_open') {
|
|
81
|
+
return new Verdict('flag', `check errored (fail-open): ${detail}`);
|
|
82
|
+
}
|
|
83
|
+
return new Verdict('block', `check errored (fail-closed): ${detail}`);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Run one guardrail's check on the async path, bounding an `async` check to `g.timeout` via
|
|
87
|
+
* `Promise.race`. A *sync* check runs inline (a sync `timeout` cannot be enforced without threads —
|
|
88
|
+
* see {@link Guardrail}). Throws propagate to the caller's `onError` mapping.
|
|
89
|
+
*/
|
|
90
|
+
async function runCheckAsync(g, payload, ctx) {
|
|
91
|
+
const result = g.check(payload, ctx);
|
|
92
|
+
if (isPromise(result) && g.timeout !== undefined) {
|
|
93
|
+
const seconds = g.timeout;
|
|
94
|
+
let handle;
|
|
95
|
+
const timeout = new Promise((_resolve, reject) => {
|
|
96
|
+
handle = setTimeout(() => reject(new GuardrailTimeoutError(`guardrail ${JSON.stringify(g.name)} check exceeded ${seconds}s`)), seconds * 1000);
|
|
97
|
+
});
|
|
98
|
+
try {
|
|
99
|
+
return (await Promise.race([result, timeout]));
|
|
100
|
+
}
|
|
101
|
+
finally {
|
|
102
|
+
if (handle !== undefined)
|
|
103
|
+
clearTimeout(handle);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return (await result);
|
|
107
|
+
}
|
|
48
108
|
/**
|
|
49
109
|
* Run the `stage` guardrails over `payload` **synchronously**. Returns `{ payload, decisions }`
|
|
50
110
|
* with any redactions applied in order; throws `GuardrailTripped` on the first block. An `async`
|
|
51
|
-
* check throws here — use {@link evaluateAsync}.
|
|
111
|
+
* check throws here — use {@link evaluateAsync}. A *throwing* sync check honours its `onError`
|
|
112
|
+
* policy; `timeout` applies to the async path only (no sync threads in JS).
|
|
52
113
|
*/
|
|
53
114
|
export function evaluate(guardrails, stage, payload, ctx) {
|
|
54
115
|
const context = ctx ?? { stage };
|
|
55
116
|
const decisions = [];
|
|
56
117
|
let current = payload;
|
|
57
118
|
for (const g of applicable(guardrails, stage)) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
119
|
+
let result;
|
|
120
|
+
try {
|
|
121
|
+
result = g.check(current, context);
|
|
122
|
+
}
|
|
123
|
+
catch (err) {
|
|
124
|
+
if (err instanceof GuardrailTripped)
|
|
125
|
+
throw err;
|
|
126
|
+
// a THROWING sync check → its on_error policy (recorded), never a swallowed exception
|
|
127
|
+
current = handle(onErrorVerdict(g, err), g, stage, current, context, decisions);
|
|
128
|
+
continue;
|
|
129
|
+
}
|
|
130
|
+
// An async check on the sync path is a misuse: this TypeError is raised OUTSIDE the on_error
|
|
131
|
+
// try above so it always propagates (parity with Python `_invoke_sync`), never mapped to a block.
|
|
132
|
+
if (isPromise(result)) {
|
|
133
|
+
void result.catch(() => { }); // swallow the rejection of the discarded promise
|
|
61
134
|
throw new TypeError(`guardrail ${JSON.stringify(g.name)} is async; use evaluateAsync`);
|
|
62
135
|
}
|
|
63
|
-
current = handle(
|
|
136
|
+
current = handle(result, g, stage, current, context, decisions);
|
|
64
137
|
}
|
|
65
138
|
return { payload: current, decisions };
|
|
66
139
|
}
|
|
67
|
-
/**
|
|
140
|
+
/**
|
|
141
|
+
* Async counterpart of {@link evaluate}: awaits `async` checks (bounded by each guardrail's
|
|
142
|
+
* `timeout`), calls sync ones directly, and applies each guardrail's `onError` policy on a
|
|
143
|
+
* throw/timeout.
|
|
144
|
+
*/
|
|
68
145
|
export async function evaluateAsync(guardrails, stage, payload, ctx) {
|
|
69
146
|
const context = ctx ?? { stage };
|
|
70
147
|
const decisions = [];
|
|
71
148
|
let current = payload;
|
|
72
149
|
for (const g of applicable(guardrails, stage)) {
|
|
73
|
-
|
|
150
|
+
let verdict;
|
|
151
|
+
try {
|
|
152
|
+
verdict = await runCheckAsync(g, current, context);
|
|
153
|
+
}
|
|
154
|
+
catch (err) {
|
|
155
|
+
if (err instanceof GuardrailTripped)
|
|
156
|
+
throw err; // a block from a nested handle propagates
|
|
157
|
+
verdict = onErrorVerdict(g, err); // throw / timeout → on_error policy (recorded)
|
|
158
|
+
}
|
|
159
|
+
// handle() throws GuardrailTripped on a block — OUTSIDE the try, so a block is never caught as
|
|
160
|
+
// an on_error (only the CHECK's own throws map to on_error).
|
|
74
161
|
current = handle(verdict, g, stage, current, context, decisions);
|
|
75
162
|
}
|
|
76
163
|
return { payload: current, decisions };
|
|
@@ -86,46 +173,58 @@ export async function applyAsync(guardrails, stage, payload, ctx) {
|
|
|
86
173
|
// --------------------------------------------------------------------------- standalone wiring
|
|
87
174
|
let installedInterceptor = null;
|
|
88
175
|
let installedSubscriber = null;
|
|
176
|
+
/**
|
|
177
|
+
* The shared interceptor body used by {@link install} and {@link scoped} — gate an `LLMCall` at the
|
|
178
|
+
* `input` stage (redact reroutes, block raises, pass declines) and a `ToolCall` at the `tool_call`
|
|
179
|
+
* stage (block raises; redact/flag recorded but the call proceeds).
|
|
180
|
+
*/
|
|
181
|
+
function gateInterceptor(gl, event) {
|
|
182
|
+
if (event instanceof LLMCall) {
|
|
183
|
+
const ctx = { stage: 'input', traceId: event.traceId };
|
|
184
|
+
const { payload, decisions } = evaluate(gl, 'input', event.messages, ctx);
|
|
185
|
+
if (decisions.some((d) => d.action === 'redact'))
|
|
186
|
+
return new Reroute({ messages: payload });
|
|
187
|
+
return MISS;
|
|
188
|
+
}
|
|
189
|
+
if (event instanceof ToolCall) {
|
|
190
|
+
const ctx = {
|
|
191
|
+
stage: 'tool_call',
|
|
192
|
+
tool: event.name,
|
|
193
|
+
toolArgs: event.arguments,
|
|
194
|
+
traceId: event.traceId,
|
|
195
|
+
};
|
|
196
|
+
evaluate(gl, 'tool_call', event.arguments, ctx); // block throws; else record + proceed
|
|
197
|
+
return MISS;
|
|
198
|
+
}
|
|
199
|
+
return MISS;
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* The shared post-flight output subscriber body: gate the completed `LLMCall`'s response text at the
|
|
203
|
+
* `output` stage (block raises after the call ran).
|
|
204
|
+
*/
|
|
205
|
+
function gateOutput(gl, event) {
|
|
206
|
+
if (!(event instanceof LLMCall))
|
|
207
|
+
return;
|
|
208
|
+
const text = responseText(event);
|
|
209
|
+
if (text === null)
|
|
210
|
+
return;
|
|
211
|
+
const ctx = { stage: 'output', traceId: event.traceId };
|
|
212
|
+
evaluate(gl, 'output', text, ctx); // block throws post-flight
|
|
213
|
+
}
|
|
89
214
|
/**
|
|
90
215
|
* Gate every instrumented call by registering ONE `@cendor/core` interceptor (+ an output
|
|
91
216
|
* subscriber). Framework-independent. Input: a block raises (nothing spends), a redact reroutes the
|
|
92
217
|
* cleaned messages, a pass declines. tool_call: a block raises; else record + proceed (tools have
|
|
93
218
|
* no message-rewrite seam). Output: a bus subscriber raises **post-flight** on a block (same
|
|
94
219
|
* overshoot semantics as tokenguard's `onExceed:"raise"`). Runs sync checks only. Call
|
|
95
|
-
* {@link uninstall} to remove.
|
|
220
|
+
* {@link uninstall} to remove. `install()` is **process-global** — for a concurrent server that
|
|
221
|
+
* varies guardrails per request, use {@link scoped} instead.
|
|
96
222
|
*/
|
|
97
223
|
export function install(guardrails) {
|
|
98
224
|
uninstall();
|
|
99
225
|
const gl = [...guardrails];
|
|
100
|
-
const interceptor = (event) =>
|
|
101
|
-
|
|
102
|
-
const ctx = { stage: 'input', traceId: event.traceId };
|
|
103
|
-
const { payload, decisions } = evaluate(gl, 'input', event.messages, ctx);
|
|
104
|
-
if (decisions.some((d) => d.action === 'redact'))
|
|
105
|
-
return new Reroute({ messages: payload });
|
|
106
|
-
return MISS;
|
|
107
|
-
}
|
|
108
|
-
if (event instanceof ToolCall) {
|
|
109
|
-
const ctx = {
|
|
110
|
-
stage: 'tool_call',
|
|
111
|
-
tool: event.name,
|
|
112
|
-
toolArgs: event.arguments,
|
|
113
|
-
traceId: event.traceId,
|
|
114
|
-
};
|
|
115
|
-
evaluate(gl, 'tool_call', event.arguments, ctx); // block throws; else record + proceed
|
|
116
|
-
return MISS;
|
|
117
|
-
}
|
|
118
|
-
return MISS;
|
|
119
|
-
};
|
|
120
|
-
const subscriber = (event) => {
|
|
121
|
-
if (!(event instanceof LLMCall))
|
|
122
|
-
return;
|
|
123
|
-
const text = responseText(event);
|
|
124
|
-
if (text === null)
|
|
125
|
-
return;
|
|
126
|
-
const ctx = { stage: 'output', traceId: event.traceId };
|
|
127
|
-
evaluate(gl, 'output', text, ctx); // block throws post-flight
|
|
128
|
-
};
|
|
226
|
+
const interceptor = (event) => gateInterceptor(gl, event);
|
|
227
|
+
const subscriber = (event) => gateOutput(gl, event);
|
|
129
228
|
addInterceptor(interceptor);
|
|
130
229
|
bus.subscribe(subscriber);
|
|
131
230
|
installedInterceptor = interceptor;
|
|
@@ -140,6 +239,98 @@ export function uninstall() {
|
|
|
140
239
|
installedInterceptor = null;
|
|
141
240
|
installedSubscriber = null;
|
|
142
241
|
}
|
|
242
|
+
//: The guardrails active in *this* execution context, or `undefined` outside any `scoped` block.
|
|
243
|
+
//: With a real `AsyncLocalStorage` installed (Node), overlapping async tasks each see their own
|
|
244
|
+
//: value; the ambient fallback is single-context (documented — not concurrency-safe).
|
|
245
|
+
let scopeStore;
|
|
246
|
+
let ambientScope;
|
|
247
|
+
let alsRequested = false;
|
|
248
|
+
/**
|
|
249
|
+
* Lazily install a real `AsyncLocalStorage`-backed scope store (Node only), so overlapping async
|
|
250
|
+
* requests stay isolated. Best-effort + idempotent: on edge/browser (`node:async_hooks` missing) it
|
|
251
|
+
* quietly keeps the ambient fallback, so `@cendor/guardrails` stays all-runtime (no `node:*` at the
|
|
252
|
+
* module top). Mirrors the spirit of `@cendor/core`'s `installTraceContext`.
|
|
253
|
+
*/
|
|
254
|
+
async function ensureAls() {
|
|
255
|
+
if (alsRequested)
|
|
256
|
+
return;
|
|
257
|
+
alsRequested = true;
|
|
258
|
+
try {
|
|
259
|
+
const { AsyncLocalStorage } = await import('node:async_hooks');
|
|
260
|
+
if (!scopeStore)
|
|
261
|
+
scopeStore = new AsyncLocalStorage();
|
|
262
|
+
}
|
|
263
|
+
catch {
|
|
264
|
+
// node:async_hooks unavailable (edge/browser) — keep the ambient fallback (single-context)
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
void ensureAls(); // best-effort auto-install so real Node usage gets concurrency-correct isolation
|
|
268
|
+
function activeScope() {
|
|
269
|
+
return scopeStore ? scopeStore.getStore() : ambientScope;
|
|
270
|
+
}
|
|
271
|
+
function scopedInterceptor(event) {
|
|
272
|
+
const gl = activeScope();
|
|
273
|
+
if (!gl || gl.length === 0)
|
|
274
|
+
return MISS; // no active scope in this context — decline
|
|
275
|
+
return gateInterceptor(gl, event);
|
|
276
|
+
}
|
|
277
|
+
function scopedSubscriber(event) {
|
|
278
|
+
const gl = activeScope();
|
|
279
|
+
if (!gl || gl.length === 0)
|
|
280
|
+
return;
|
|
281
|
+
gateOutput(gl, event);
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Register the context-gated interceptor + subscriber (idempotent — `addInterceptor` / `bus.subscribe`
|
|
285
|
+
* de-dupe). They stay registered and are no-ops outside a {@link scoped} block, so leaving them
|
|
286
|
+
* installed costs a store lookup per call and needs no teardown.
|
|
287
|
+
*/
|
|
288
|
+
function ensureScopedSeam() {
|
|
289
|
+
addInterceptor(scopedInterceptor);
|
|
290
|
+
bus.subscribe(scopedSubscriber);
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Gate every instrumented call for the duration of `fn` — like {@link install}, but **scoped to the
|
|
294
|
+
* current execution context** rather than process-global. Runs `fn` with `guardrails` active and
|
|
295
|
+
* returns its result (sync or a `Promise`); the previous scope is restored on exit.
|
|
296
|
+
*
|
|
297
|
+
* With a real `AsyncLocalStorage` (auto-installed on Node), a concurrent server (async tasks) can
|
|
298
|
+
* vary guardrails per request without one request's set leaking into another. On edge/browser the
|
|
299
|
+
* fallback is a save/restore module variable — correct for sequential/nested use, **not**
|
|
300
|
+
* concurrency-safe. Nest freely — an inner `scoped` replaces the set for its block. Runs sync checks
|
|
301
|
+
* only (the seam is sync).
|
|
302
|
+
*
|
|
303
|
+
* ```ts
|
|
304
|
+
* await scoped([rules.keywordDeny(['secret'], { action: 'block' })], async () => {
|
|
305
|
+
* await client.chat.completions.create(...); // gated here
|
|
306
|
+
* });
|
|
307
|
+
* ```
|
|
308
|
+
*/
|
|
309
|
+
export function scoped(guardrails, fn) {
|
|
310
|
+
ensureScopedSeam();
|
|
311
|
+
void ensureAls();
|
|
312
|
+
const gl = [...guardrails];
|
|
313
|
+
if (scopeStore)
|
|
314
|
+
return scopeStore.run(gl, fn);
|
|
315
|
+
// Ambient fallback (single-context): save/restore, honouring sync or async `fn` like core's trace.
|
|
316
|
+
const previous = ambientScope;
|
|
317
|
+
ambientScope = gl;
|
|
318
|
+
let result;
|
|
319
|
+
try {
|
|
320
|
+
result = fn();
|
|
321
|
+
}
|
|
322
|
+
catch (err) {
|
|
323
|
+
ambientScope = previous;
|
|
324
|
+
throw err;
|
|
325
|
+
}
|
|
326
|
+
if (result instanceof Promise) {
|
|
327
|
+
return result.finally(() => {
|
|
328
|
+
ambientScope = previous;
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
ambientScope = previous;
|
|
332
|
+
return result;
|
|
333
|
+
}
|
|
143
334
|
function get(obj, name) {
|
|
144
335
|
return obj != null && typeof obj === 'object'
|
|
145
336
|
? obj[name]
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file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IAAI,CAAC;IAClD,MAAM,UAAU,GAAG,GAAG,CAAC,GAAG,CAAC,QAAQ,EAAE,QAAQ,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,mBAAmB;IAC/E,MAAM,UAAU,GAAG,GAAG,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;IAC9C,IAAI,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,EAAE,CAAC;QAC9B,MAAM,KAAK,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC;QAC7E,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC;YAAE,OAAO,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IAC1D,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/dist/judge.d.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LLM-judge helpers — turn a bring-your-own model call into a usable guardrail. The TS port of
|
|
3
|
+
* `cendor.guardrails.judge`.
|
|
4
|
+
*
|
|
5
|
+
* cendor ships **no** classifier. `rules.llmJudge` is an adapter *contract*: you supply the model
|
|
6
|
+
* call. These helpers give that call the boring, error-prone parts so you don't hand-roll them —
|
|
7
|
+
*
|
|
8
|
+
* - {@link verdictPrompt} — a strict system instruction that pins the model to a two-field JSON
|
|
9
|
+
* verdict (`{"trip": <bool>, "reason": "<short>"}`), so the output is parseable, not prose.
|
|
10
|
+
* - {@link parseVerdict} — strict JSON → `Verdict` (or `null` to pass). Malformed output *throws* so
|
|
11
|
+
* the guardrail's `onError` policy decides (a garbled judge fails **closed** by default).
|
|
12
|
+
* - {@link judge} — glue the two around your `respond(system, user)` callable (sync or async) into a
|
|
13
|
+
* check you hand straight to `rules.llmJudge`.
|
|
14
|
+
*
|
|
15
|
+
* The judge's own spend is budgeted and audited: make the call through an `instrument()`-ed client
|
|
16
|
+
* and its tokens + cost land in tokenguard / acttrace like any other call.
|
|
17
|
+
*/
|
|
18
|
+
import { type Context, Verdict } from './decision.js';
|
|
19
|
+
/** A `respond(system, user)` model callable (sync or async) — returns the assistant's reply string. */
|
|
20
|
+
export type Respond = (system: string, user: string) => string | Promise<string>;
|
|
21
|
+
/**
|
|
22
|
+
* The default judge instruction. `{policy}` is filled with your risk description. It pins the model
|
|
23
|
+
* to strict JSON so {@link parseVerdict} can read it — no chain-of-thought, no prose.
|
|
24
|
+
*/
|
|
25
|
+
export declare const DEFAULT_SYSTEM: string;
|
|
26
|
+
/**
|
|
27
|
+
* Build the judge's system instruction for `policy` (a plain-language description of what should
|
|
28
|
+
* trip). Override `template` to customise, keeping the `{policy}` placeholder and the strict-JSON
|
|
29
|
+
* verdict contract {@link parseVerdict} expects.
|
|
30
|
+
*/
|
|
31
|
+
export declare function verdictPrompt(policy: string, template?: string): string;
|
|
32
|
+
/**
|
|
33
|
+
* Parse a strict-JSON judge reply into a `Verdict` (trip) or `null` (pass). Expects
|
|
34
|
+
* `{"trip": <bool>, "reason": "<short>"}`. Trips with `action` (default `"block"`) and the model's
|
|
35
|
+
* reason. **Throws** on malformed output — deliberately: a judge whose output can't be read must not
|
|
36
|
+
* silently pass, so the caller's `onError` policy (fail-closed by default) decides. See {@link judge}.
|
|
37
|
+
*/
|
|
38
|
+
export declare function parseVerdict(text: string, opts?: {
|
|
39
|
+
action?: 'block' | 'redact' | 'flag';
|
|
40
|
+
}): Verdict | null;
|
|
41
|
+
/**
|
|
42
|
+
* Compose {@link verdictPrompt} + your model call + {@link parseVerdict} into a check ready for
|
|
43
|
+
* `rules.llmJudge`.
|
|
44
|
+
*
|
|
45
|
+
* `respond(system, user)` is *your* callable — sync or async — that runs one model call given the
|
|
46
|
+
* system instruction and the payload text, and returns the assistant's reply string. Make that call
|
|
47
|
+
* through an `instrument()`-ed client and its cost is budgeted + audited.
|
|
48
|
+
*
|
|
49
|
+
* ```ts
|
|
50
|
+
* import { judge, rules } from '@cendor/guardrails';
|
|
51
|
+
*
|
|
52
|
+
* const respond = async (system: string, user: string): Promise<string> => {
|
|
53
|
+
* const r = await client.chat.completions.create({
|
|
54
|
+
* model: 'gpt-4o-mini',
|
|
55
|
+
* messages: [{ role: 'system', content: system }, { role: 'user', content: user }],
|
|
56
|
+
* });
|
|
57
|
+
* return r.choices[0].message.content ?? '';
|
|
58
|
+
* };
|
|
59
|
+
*
|
|
60
|
+
* const check = judge.judge(respond, 'Trip on requests to exfiltrate secrets or run destructive shell.');
|
|
61
|
+
* const guardrail = rules.llmJudge(check, { timeout: 8 });
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export declare function judge(respond: Respond, policy: string, opts?: {
|
|
65
|
+
action?: 'block' | 'redact' | 'flag';
|
|
66
|
+
template?: string;
|
|
67
|
+
}): (payload: unknown, ctx: Context) => Promise<Verdict | null>;
|
|
68
|
+
/**
|
|
69
|
+
* The default *task-adherence* instruction. `{instruction}` is filled with the user's originating
|
|
70
|
+
* request (from `Context.instruction`); the proposed tool call is passed as the user message. It pins
|
|
71
|
+
* the model to the same strict-JSON verdict {@link parseVerdict} reads, where `trip=true` means the
|
|
72
|
+
* tool call is **misaligned** with the instruction.
|
|
73
|
+
*/
|
|
74
|
+
export declare const ADHERENCE_SYSTEM: string;
|
|
75
|
+
/**
|
|
76
|
+
* A **bring-your-own-judge** task-adherence check for the `tool_call` stage: *given the user's
|
|
77
|
+
* instruction and this proposed tool call + arguments, is the action aligned with intent?* Returns a
|
|
78
|
+
* check ready for `rules.llmJudge` (like {@link judge}). Reads the user's instruction from
|
|
79
|
+
* `Context.instruction` and the proposed call from `ctx.tool` / `ctx.toolArgs` (or the payload),
|
|
80
|
+
* calls your `respond(system, user)`, and parses a strict-JSON verdict — `trip=true` means
|
|
81
|
+
* *misaligned*. Defaults to `action:'flag'` (advisory). No adherence-rate claim: a BYO judge, only
|
|
82
|
+
* as good as your model + prompt.
|
|
83
|
+
*
|
|
84
|
+
* > 🚧 The `@cendor/sdk` auto-threading of the user turn into `ctx.instruction` is a deferred parity
|
|
85
|
+
* > tail — set `ctx.instruction` yourself until it lands. See docs/guardrails.md "Task adherence".
|
|
86
|
+
*/
|
|
87
|
+
export declare function taskAdherence(respond: Respond, opts?: {
|
|
88
|
+
action?: 'block' | 'redact' | 'flag';
|
|
89
|
+
template?: string;
|
|
90
|
+
}): (payload: unknown, ctx: Context) => Promise<Verdict | null>;
|
|
91
|
+
//# sourceMappingURL=judge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"judge.d.ts","sourceRoot":"","sources":["../src/judge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,EAAE,KAAK,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAEtD,uGAAuG;AACvG,MAAM,MAAM,OAAO,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAEjF;;;GAGG;AACH,eAAO,MAAM,cAAc,QAK4C,CAAC;AAExE;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,GAAE,MAAuB,GAAG,MAAM,CAEvF;AA8BD;;;;;GAKG;AACH,wBAAgB,YAAY,CAC1B,IAAI,EAAE,MAAM,EACZ,IAAI,GAAE;IAAE,MAAM,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,MAAM,CAAA;CAAO,GAClD,OAAO,GAAG,IAAI,CAUhB;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,KAAK,CACnB,OAAO,EAAE,OAAO,EAChB,MAAM,EAAE,MAAM,EACd,IAAI,GAAE;IAAE,MAAM,CAAC,EAAE,OAAO,GAAG,QA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