Skip to content
SamplePreview build: teacher profiles, ratings, reviews and lesson counts are sample data.
All tutors

Getting Reliable JSON Out of a Model

Get model output your code can parse: schemas, validation, truncation handling and safe retries.

By Greta Lindqvist Beginner Building with LLM APIs 4.5(2) 32 lessons taught Sample

Your first 3 replies from the tutor are free. Then you can continue the lesson for $5 from your credit.

A taste of a lesson

One question and the answer, as this tutor gives it.

Getting Reliable JSON Out of a Model AI tutor following Greta Lindqvist's plan
Student:

When an email has no invoice number, the model makes one up. How do I stop it?

Tutor:

Give it an honest way out. Make invoice_number nullable in your schema and say in the instructions: if the email does not state an invoice number, return null; never guess or construct one. Models invent values partly because the format seems to demand something. Then add a check in code: if an invoice number does not appear in the source text, treat it as suspicious. Test with five emails that lack numbers. How many come back null after the change?

Written by the teacher as an example. In your lesson the tutor answers your own questions, and like any AI it can be wrong.

What you will be able to do

  • Compare prompt instructions, JSON modes, schema constraints and tool based structure
  • Design schemas with enums, required fields and nulls for missing data
  • Validate every response for syntax, schema and business rules
  • Handle truncation, refusals and wrapped JSON without string hacks
  • Retry failed outputs by feeding back the validation error

Lesson plan

5 lessons. Pick one to start there.

  1. 1 Why structure matters See how free text breaks code and what structured output gives you. Start
  2. 2 Ways to get structured output Choose between format instructions, JSON modes, schema constraints and tools. Start
  3. 3 Designing a schema the model fills well Write a clear schema with sensible types, enums and nullable fields. Start
  4. 4 Validating every response Check syntax, schema and business rules before using output. Start
  5. 5 Failures and recovery Handle truncation, refusals and wrapped JSON and retry sensibly. Start

Try asking

Tap a question to start a lesson with it.

About this tutor

For beginners building apps where the model's answer feeds into code: extracting fields, filling a form, producing a list of items. You learn the main ways to get structured output (format instructions, JSON modes, schema constrained output where a provider supports it, and tool definitions used as a structure), how to design a schema the model fills well, and why you must still validate every response. The tutor covers the failures that break apps in practice: text around the JSON, truncated output, invented values for missing fields and refusals, plus how to retry with the validation error instead of patching strings.

Reviews

4.5

2 ratingsSample

  • Agnieszka P.Sample

    The truncation lesson explained our random parse errors: max tokens too low. Clear comparison of the different structured output options.

  • Rui C.Sample

    Nullable fields plus a check that the value appears in the source text cut our invented invoice numbers to almost none. Simple and effective.

About the teacher

Greta Lindqvist

Structured output, tool calling and safe input handling for LLM applications that must behave predictably

9 tutors 4.5(18) 308 lessons taught Sample

I teach the parts of LLM apps where free text has to meet real software: JSON that must parse, tools the model calls, images and documents coming in, and users who send things you did not plan for. I spent years writing integrations between messy systems, which taught me to treat every input as untrusted and every output as something...

See Greta's profile and tutors