stage S73h
Output Validation & Constrained Generation (CFG)
Pair grammar-constrained decoding (where supported) with mandatory server-side Pydantic/JSON Schema validation (`D6`) and context-aware HTML/Markdown sanitization at the rendering sink. Never execute model-generated SQL or shell code directly.
Stage detail
When: Schema validation Weeks 1--2; constrained decoding conditional on the project requirement after core work.
- JSON Schema/Pydantic validation, strict parsing, allowlisted output fields, and safe failure paths.
- HTML/Markdown sanitization and context-aware output encoding in the frontend.
- Never execute model-generated code or SQL directly.
- Understand grammar-constrained decoding and context-free grammars conceptually.
- Explore NeMo Guardrails or another framework only after application-level validation exists.
Practice: require structured outputs for tool arguments and API responses. If the UI must not render links or code, disable/sanitize those renderers in the application. Regex or decoding constraints alone cannot enforce all downstream safety.
Do not learn yet: token-level constrained decoding internals unless you control the model/runtime or have a concrete requirement.
Study days for this stage
6- 4LLM Internals & Token BudgetsW1S1S7M1R01 R04 R07 R11
- 6Implement a small tool registry with calculate and search_notesW1S3S7R01 R07
- 31JSON-RPC & Schema ValidationW6S3S7D2R02 R07 R21
- 52Implement output validation with Pydantic/JSON SchemaW9S7D6R07 R30
- 53Study grammar-constrained generation and structured decodingW9S7D6R07 R30
- 81Provenance, ACLs & Multi-Hop ResearchW14S4S7M3D3D5D6D10R04 R05 R09 R13 R14