All posts

"Validate, don't trust: handling structured LLM output in TypeScript and Python"

The model returned clean JSON every time in development, so you shipped. Then production sent it something weird. Structured-output modes guarantee the shape of a response, never the truth of it — here is the validation discipline that keeps model output from corrupting your system, in both TypeScript and Python.

AI engineering5 min read13 July 2026by Ahmed
"Validate, don't trust: handling structured LLM output in TypeScript and Python"

There is a specific kind of bug that only appears after you ship an LLM feature. In development the model returned clean JSON every time, the demo worked, and the integration looked finished. Three weeks into production, an unusual input comes through, the model returns the amount as the string "twelve thousand" instead of a number, your parser throws, and the job dies quietly in a queue nobody is watching. Or worse — it doesn't throw, and the bad value lands in your database.

Have an AI feature stuck between demo and production?

The gap — reliability, evals, cost control, the plumbing that keeps it running unattended — is exactly the work I do. If that sounds familiar, a short conversation is usually enough to point you the right way.

Book a free consultation

© 2026 Ahmed Fareed. All rights reserved.

LOADING