Gates are the core primitive in Pecta. Each gate is a single pass/fail check that runs against an agent’s output before it reaches the user. You compose any number of gates when you callDocumentation Index
Fetch the complete documentation index at: https://docs.pecta.ai/llms.txt
Use this file to discover all available pages before exploring further.
createEngine, and the engine runs all of them in parallel under a shared timeout budget. Fail-fast (the default) aborts remaining gates the moment one fails, keeping evaluation latency low.
All built-in gates
| Gate | Category | What it checks |
|---|---|---|
gates.latency | General | ctx.latency_ms exceeds a configurable maxMs threshold |
gates.schema | General | ctx.output matches a Zod schema you provide |
gates.filesystem | General | Destructive rm commands, path traversal, and sensitive directories |
gates.pii | General | Email addresses, SSN-shaped strings, and phone numbers in output |
gates.content | General | Empty output and AI refusal/disclaimer phrases |
gates.rtb.tmaxGuard | RTB | Skips downstream gates when the OpenRTB tmax deadline is exhausted |
gates.rtb.impidMatch | RTB | Every bid.impid matches a request imp.id |
gates.rtb.adomainVerify | RTB | Placeholder or malformed advertiser domains |
gates.rtb.bidSanity | RTB | Bid price is not unrealistically far above the floor price |
gates.rtb.audienceSafety | RTB | Child-directed inventory does not receive unsafe ad categories |
gates.rtb.bcatCompliance | RTB | Response creative does not appear in the request bcat block list |
Composing gates
Pass agates array to createEngine. The engine validates that every gate has a unique name and a run function, then returns an Engine object whose evaluate method you call for each agent output.
EvaluationResult:
Timeout budget
Thetimeout option (default 50 ms) is a wall-clock budget shared across all gates. When the budget expires, the engine fires an AbortController signal. Gates that check signal.aborted before doing expensive work return immediately; any gate that is still running when the timer fires has its result recorded as passed: false with reason: "pecta:aborted: pecta:timeout".
Fail-fast behavior
WhenfailFast is true (the default), the engine aborts the shared AbortController the instant a gate returns passed: false. Gates that have not yet returned will see signal.aborted === true. The engine still waits for every Promise to settle, but aborted gates complete almost immediately. Total evaluation latency is therefore dominated by the first failing gate, not the full gate set.
Set failFast: false if you want verdicts from every gate regardless of earlier failures — useful for auditing or debugging.
A gate that returns
skipped: true is treated as passing. The tmaxGuard RTB gate uses this to opt out of evaluation when the OpenRTB deadline is already exhausted.