mediumDesignScenarioMidSeniorStaff
Your code needs JSON back from the model and it has to parse every time. How do you make that happen?
4 min readUpdated 2026-08-15
Answer
Short answer
Constrain the decoder to a schema instead of asking for JSON in prose, reserve enough output tokens that a complete document fits, validate at the boundary, and allow one repair retry that quotes the exact violation back.
Was this answer helpful?
Likely follow-ups
- Constrained decoding guarantees shape but not sense. What kinds of wrong output does it still let through?
- Your schema has a free-text `reason` field of unbounded length. What does that do to your token reservation?
- How would you handle a case where the model legitimately cannot answer and there is no valid object to return?
- What changes if you need the structured result streamed rather than returned whole?
Related questions
- A churn model scores 0.94 AUC offline and barely beats the baseline in production. One of its strongest features is populated by a process that runs after the customer has already churned. Explain what happened and how you would fix it.mediumAlso on validation5 min
- How do you decide between prompting, retrieval and fine-tuning?mediumAlso on prompting5 min
- This form marks invalid fields with red text and a red border. What has to change?mediumAlso on validation4 min
- How do you know a problem is real before you build anything to solve it?mediumAlso on validation5 min