Skip to content
Roadmap0/111
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.