Expand description
The gate framework (SPEC §8 — the moat).
A gate inspects a candidate ModelResponse and returns a GateResult verdict. Gates are
async because a real gate is I/O: a subprocess plugin (§8.1), an LLM judge, a test run.
Pure inline gates (non-empty, json-valid, schema) simply don’t await. Gate execution is
wrapped by an error budget (GateHealth): a gate that errors too often is auto-disabled
with an alarm, so a broken gate can neither silently fail closed (burns money) nor silently
fail open (burns trust) (§7.2).
Structs§
- Gate
Health - Rolling per-gate error budget (§7.2, §8.3.4). Tracks the last
windowoutcomes; once the error (abstain) fraction over a full window exceedsmax_error_rate, the gate is auto-disabled and an alarm is logged. A disabled gate is skipped by the runner (its verdict stops counting) rather than silently failing open or closed. - Gate
Health Registry - Per-gate error budgets for a running proxy (app-level, shared across requests). Lookup by gate id; unknown gates default to enabled with no accounting (a gate the operator didn’t register a budget for is simply never auto-disabled).
- Json
Valid Gate - Passes only if the completion parses as JSON. Useful for structured-output routes.
- NonEmpty
Gate - Fails an empty (whitespace-only) completion. The cheapest possible sanity gate.
- Schema
Gate - Validates the candidate (parsed as JSON) against a minimal JSON-Schema subset: top-level
type,required, and per-propertytype. Covers tool-call args and extraction tasks.
Traits§
- Gate
- A verification gate. Object-safe + async so subprocess/model gates fit the same contract.
Functions§
- aggregate
- Aggregate per-gate verdicts into the attempt’s overall verdict.
- resolve_
gates - Resolve a route’s gate ids into runnable gates. Built-in ids (
non-empty,json-valid) map to inline gates; any other id is looked up among the config’s[[gate]]definitions and built as either aSubprocessGate(acmdgate, SPEC §8.1) or aJudgeGate(ajudgegate, §8.3). The judge needs a provider (fromregistry) and the caller’s credentials (auth, BYOK). An id that is neither built-in nor defined — or a judge whose provider isn’t registered — is skipped with a warning rather than failing the request.