Skip to main content

Interface: IGuardrailsConfig

Defined in: internal/guardrails/types.ts:20

Configuration of the Guardrails. Lands in IAIGatewayConfig.guardrails. Fixed at construction: other rules need a new gateway.

Properties​

inputRules?​

optional inputRules?: IInputRule[]

Defined in: internal/guardrails/types.ts:30

The app's rules on the prompt (moderation, a topic filter, …). They run after the built-in rules (prompt not empty, not over maxPromptChars, no prompt-injection markers) and only when those passed. An ERROR issue returns FAILED and the prompt is not stored. Names are unique, also against the built-in rules. Default none.


maxPromptChars?​

optional maxPromptChars?: number

Defined in: internal/guardrails/types.ts:22

Reject longer prompts. Default 20_000.


onRuleError?​

optional onRuleError?: TOnRuleErrorHandler

Defined in: internal/guardrails/types.ts:50

The developer's channel for failed rules: a rule threw (its own code, its service, a judge that answered out of shape) or gave no answer within its timeout.

One place to log, count or alert on broken rules, instead of a callback on every rule.

Called once per failed rule, built-in rules included, fire-and-forget: the check never waits for it, and a handler that throws is logged and ignored. With or without a handler, every failure is logged on the server, and the caller gets only the short ERROR issue rule_error (IRuleErrorReport.issue). Never called for a call the caller aborted, nor for a judge call the usage adapter refused: neither is a failure of the rule.

Example​

report => logger.error({rule: report.ruleName, stage: report.stage, failure: report.failure, error: report.error}) - one log line per broken rule, with the error the caller never sees

outputRules?​

optional outputRules?: IOutputRule[]

Defined in: internal/guardrails/types.ts:36

The app's rules on the answer (business checks such as sums or ids, grounding, moderation). They run after the built-in output checks (schema, truncation) and only when those passed. An ERROR issue returns FAILED and the answer is not stored (in a run, the tool turns stay: the tools did run, D70). Names are unique. Default none.


ruleTimeoutMs?​

optional ruleTimeoutMs?: number

Defined in: internal/guardrails/types.ts:24

Time a rule may take before it counts as failed (ERROR rule_error); a rule's own timeoutMs wins. Default 10_000.