Output Validation

You will understand what output validation is, why LLM responses need it, and how to apply it in a Spring Boot service so your app stays stable even when the model surprises you.

Why This Matters

You're building a feature for EngineerPrep's lesson-generation pipeline. The pipeline asks Claude to produce a structured lesson plan — a JSON object with fields like title , chapters , and difficulty . Your Spring Boot service deserializes that JSON into a Java record and passes it downstream. It works great in testing. You ship it. Two days later the pipeline silently produces broken lessons. Claude returned a Markdown code block around the JSON — triple backticks and all. Jackson couldn't parse it. The downstream step swallowed the error quietly, and garbage got written to the database. You think: tighten the prompt. You do. It helps — for a while. But LLMs are not deterministic. The same prompt can produce different output on different calls, and production traffic surfaces inputs your tests never anticipated.…

The Simple Idea

Output validation means checking that what you received matches what you expected — and deciding what to do when it doesn't. Think of it like a quality inspector on a factory line. The machine (the LLM) produces parts. Most parts come out fine. But occasionally one is the wrong shape. The inspector doesn't let malformed parts move down the line — they flag it and send it back for rework. In your Spring Boot service, you are the inspector. After every LLM call, you check the response before trusting it. There are two levels of checking: Structural validation — does the response have the right shape? For a JSON response: is it valid JSON? Does it have all the required fields? Are the field types correct? Semantic validation…

See It in Action

Imagine the EngineerPrep lesson pipeline as a short conveyor belt with three stations. Station 1 — The LLM call Your service sends a prompt to Claude via Amazon Bedrock. Claude responds with a chunk of text. At this point it's just a raw string — your code has no idea yet whether it's valid JSON, a poem, or something in between. The string arrives and sits at Station 1 waiting to be inspected. Station 2 — Structural check The raw string moves to the structural checker. This station tries to parse the string as JSON and map it onto your Java record (for example, LessonPlanResponse ). Two things can happen: - Pass : the string is valid JSON and every required field is present. The object moves forward. - Fail : the string is malformed JSON, or a required field is missing. The checker flags it. The pipeline logs the raw response and schedules a retry…