Week 5 · LLM gateways · about 3 minutes
What you will be able to do
Enforce a schema on model output for Helix, then retry once when the JSON is invalid.
The idea
Downstream code needs a contract: answer text and citation IDs, not free prose. Validate against a schema. On failure, retry once with the error — then fail closed.
Structured output modes help, but you still validate. Trust the parser, not the model's manners.
import json
REQUIRED = {"answer", "citations"}
def parse_or_raise(text: str) -> dict:
data = json.loads(text)
if not REQUIRED.issubset(data):
raise ValueError("schema")
return dataIf it is not valid JSON for your schema, it is not an answer.
Key takeaways
- Define required fields up front.
- Validate every completion.
- Retry once on schema failure; then fail closed.
Part of the Forward Deployed Engineer roadmap. New to the role? Start with what a Forward Deployed Engineer does.