End-to-End Safety Gate
Lifecycle
- pre-gen - run the lesson 83 detector on the prompt
- if confidence >= block_threshold: return refusal, emit trace, stop
- during-gen - stream from the model, buffer two chunks, scan for known harmful continuations
- if matched: terminate iterator, mark trace, treat as medium severity
- post-gen - if no early termination, run the lesson 85 classifier router and the lesson 86 rules engine on the completed output
- aggregate - take the maximum severity across pre, during, post.classifier, post.rules
- apply - map to block, redact, warn, or allow
Aggregation table
| Signal state | Action |
|---|---|
| any high severity | block |
| any medium severity | redact |
| any low severity | warn |
| nothing | allow |
Trace structure
text
RequestTrace
request_id: str
prompt: str
pre_gen: { category, confidence, fired[] }
during_gen: { terminated_early, matched_pattern, partial_chunks }
post_gen: { classifier_action, classifier_severity, rules_max_severity, rules_violations[] } | null
final_action: block | redact | warn | allow
final_output: str
latency_ms: floatArtifact
outputs/gate_trace.json contains the summary and one trace per request, including 50 taxonomy fixtures and 10 benign prompts.