Semantic, Output, and Budget Rules
This page covers rules that need the whole candidate or the full request shape: natural-language semantic policies, structured output contracts, and context-size budgets.
Semantic policy#
provon.guard.semantic runs on input, output, or both, and supports audit and block. Instead of one
fixed scenario check, the plugin carries a policies[] array: each entry is an independent
natural-language policy with its own model, directions, categories, and failure choice.
Policy fields#
| Field | Purpose |
|---|---|
id |
Unique policy id; stored as the match category and required to be non-empty and distinct |
action |
audit or block; transform is rejected with 400 because a judgement needs the whole candidate |
model |
Any Gateway model route the project can reach; judge calls skip guardrails and cannot recurse |
policy |
The admin-written policy text the checker judges against, handed over verbatim |
directions |
input, output, or both (default both) |
categories |
Closed category list handed to the checker |
onCheckerError |
closed (default) blocks on checker failure; open records the failure and allows |
Off mode yields an empty policy list and the plugin no-ops. A non-empty array is required in audit
and enforce; every structural problem fails at settings write time with semantic_misconfigured.
Bounded check payload#
| Bound | Default | Meaning |
|---|---|---|
maxSegmentBytes |
262144 |
Hard cap on buffered wire bytes per segment |
maxSegmentDurationMs |
30000 |
Hard wall-clock cap on buffering |
checkerTimeoutMs |
15000 |
Abortable timeout for one checker call |
maxContextChars |
12000 |
Context string truncation length |
maxCheckerOutputTokens |
512 |
Tokens the checker itself may spend |
When the checker model declares a context window, the effective context budget is the smaller of the admin cap and the window-derived budget.
What the checker sees#
The checker sees only what the boundary owns: the current output's text and tool-call arguments, plus assembled conversation context. System and developer instructions and every user message are kept whole; the context budget trims only older assistant actions, tool results, and tool names, oldest first. Trimmed amounts are recorded as counts on the match evidence — never as content. The semantic rule does not control the host's MCP servers, browser, shell, or filesystem.
Enforcement semantics#
- In Audit the exchange passes and the decision merges into the request span.
- In Enforce an output check buffers each segment until the checker returns; complete outputs are never truncated — the caps bound what is sent to the checker, not what reaches the caller.
- A checker failure, timeout, or oversized input records the decision and rejects the exchange in Enforce; in Audit the same conditions only record it. Buffer-cap failures always block, because once the upstream stream was cancelled there are no bytes left to deliver.
- A rejected exchange does not ban the session or API key; the next request is evaluated fresh.
- Supported endpoint shapes are chat completions, responses, and messages. On unsupported shapes
Enforce returns
409rather than passing unchecked; upstream non-2xx responses pass through unchanged with fixed guardrail evidence.
Match evidence carries the checker reason, buffered bytes, buffering duration, and trimmed counts; it never contains the request, output, or policy text.
Structured output validation#
provon.guard.structured-output is output-only and supports audit and block, without rewriting
values or retrying the model. It validates answers against the request-declared JSON Schema in:
- Chat Completions
response_format.json_schema.schema; - Responses
text.format.schema; - Messages
output_config.format.schema.
No request schema means not_evaluated, not an imposed output format. Enforcement holds delivery
until the complete response is validated, while audits inspect a bounded background copy. The same
schema bounds and rejection rules as tool argument validation
apply: 32 KiB / 512 nodes / depth 32 for schemas, 10,000 nodes / depth 32 for values, no coercion,
no remote references, and a schema_unavailable decision for invalid schemas.
Context budgets#
Three input-only rules keep requests inside cost and footprint limits:
| Plugin id | Rule | Purpose |
|---|---|---|
provon.guard.message-history-size |
Conversation footprint | Cap message count, tool calls, and tool-definition size |
provon.guard.estimated-input-tokens |
Prompt token budget | Block requests over an estimated input-token limit |
provon.guard.max-completion-tokens |
Response token budget | Audit, cap, or block requested completion tokens |
Input token checks are estimates. API-key token policies perform their own admission reservation and settle against provider-reported usage when available; the two controls complement rather than replace each other.
max-completion-tokens is the only budget rule with a Transform action: instead of blocking, it
rewrites the request's completion parameter down to the configured cap. Hard resource ceilings and
rate or spend budgets remain usage-limit concerns — see Gateway limits.