Overview
The Content Judge is a safety layer that screens user queries before scene generation. It uses an LLM to classify queries as safe, sensitive, or harmful, helping maintain educational standards while allowing historically significant but mature content.The Judge is always available but requires an
OPENROUTER_API_KEY to function. Queries are blocked if the Judge is unavailable.ContentJudge Class
Configuration
Environment Variables
Screening Queries
The primary method isscreen(), which returns a verdict:
Return Values
Moderation Prompt
The Judge uses a carefully designed prompt:Design Principles
- Educational first: Prioritize historical significance over comfort
- Context-aware: Distinguish between educational and exploitative content
- Transparent: Always provide a reason for the verdict
Example Classifications
Approve
Sensitive
Reject
Integration with JobManager
The Judge is typically invoked at the start of scene generation:Response Parsing
The Judge handles markdown-wrapped JSON:Logging
All screening decisions are logged:Error Handling
Fail-Safe Behavior
The Judge always defaults to rejection on errors:- API failures
- Timeout
- Invalid JSON
- Unknown verdict values
Performance
- Timeout: 60 seconds per query
- Model: Gemini 2.0 Flash (fast inference)
- Cost: ~0.10)
Screening adds ~1-2 seconds of latency to each generation request. This is acceptable for the safety benefits.
Customization
To use a different model or adjust the prompt:JUDGE_PROMPT in app/workers/judge.py to adjust classification criteria.