Stop Begging Your LLM for Valid JSON: Self-Correcting Structured Output in Spring AI 2.0 Spring AI 2.0 introduces self-correcting structured output that automatically validates JSON responses from LLMs and retries with error feedback when the output is malformed. The feature, demonstrated by Spring Developer Advocate Dan Vega, uses a single method call to enable a retry loop that catches deserialization errors and prompts the model to fix them. Christian Tzolov of the Spring AI team documented the validation loop, which defaults to three retry attempts and can be customized. Every developer who has worked with LLMs has been there. You ask the model for JSON. You describe the schema. You say "please only respond with valid JSON." And sometimes, it still breaks. Your application crashes because the model returned a string where you expected an integer. Or it wrapped the JSON in markdown code blocks. Or it omitted a required field. Spring AI 2.0 has a solution that treats this like a real engineering problem instead of a prayer. When you use structured output in Spring AI, the workflow goes like this: This works well with frontier models like Claude and GPT-4. But smaller open-source models, like Llama 3.2 1B running locally via Ollama, fail more often. They might return null for a primitive field, omit required fields, or produce malformed JSON. When it fails, you get a deserialization exception. Your endpoint returns a 500 error. Spring AI provides no built-in recovery mechanism. Consider a conference talk submission system. Speakers submit messy, unstructured abstracts. You want to extract structured data: public record TalkSubmission String title, String abstractText, Level level, // BEGINNER, INTERMEDIATE, ADVANCED Track track, int duration, List