---
title: "Discussion on \"Valid JSON, Wrong Refund: Structured LLM Outputs in Django (Part 7)\" | Hashnode"
description: "Discussion on \"Valid JSON, Wrong Refund: Structured LLM Outputs in Django (Part 7)\". Constrained decoding guarantees shape, not truth: four validation layers, fact checks through Pydantic validation context, one model for Anthropic and OpenAI schemas, and a retry policy that knows when to stop."
url: "https://hashnode.com/posts/structured-llm-outputs-pydantic-django/6afcd459c7d39edf63adb6b0"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Valid JSON, Wrong Refund: Structured LLM Outputs in Django (Part 7)](https://aidevpro.hashnode.dev/structured-llm-outputs-pydantic-django?utm_source=hashnode&utm_medium=feed)

Constrained decoding guarantees shape, not truth: four validation layers, fact checks through Pydantic validation context, one model for Anthropic and OpenAI schemas, and a retry policy that knows when to stop.

21h ago · 18 min read · aidevpro.hashnode.dev  
Read the article

-   [#django](https://hashnode.com/tag/django)
-   [#pydantic](https://hashnode.com/tag/pydantic)
-   [#ai-agents](https://hashnode.com/tag/ai-agents)
-   [#llmops](https://hashnode.com/tag/llmops)
-   [#python](https://hashnode.com/tag/python)

## Written by

[AI Developer](https://hashnode.com/@lycore)

@lycore

  
[View profile](https://hashnode.com/@lycore)

build production-ready AI integrations, mobile apps, and web platforms for businesses that want real results.

Custom software & AI development company. We build production-ready AI integrations, mobile apps, and web platforms for businesses that want real results. lycore.com

## Responses 2

Markdown supported · ⌘↵ to post

[Dr Srinivas Padmanabhuni](https://hashnode.com/@srinivaspadmanabhuni)

[13h ago](https://hashnode.com/posts/structured-llm-outputs-pydantic-django/6afcd459c7d39edf63adb6b0/comment/6afd43459a49bb4f2637db4c)

The refund example where schema-valid JSON cites a knowledge-base chunk that retrieval never returned is a sharp way to show that shape and truth are different checks. Your rule that the same error twice means stop resonates: in one shopping-agent trace I looked at, the agent called open\_url with the identical search URL more than ten times and ended with an empty answer. Checking the tool-call sequence, not just the final output, is what exposed that retry storm.

[AI Developer](https://hashnode.com/@lycore)

[7h ago](https://hashnode.com/posts/structured-llm-outputs-pydantic-django/6afcd459c7d39edf63adb6b0/comment/6afd43459a49bb4f2637db4c#reply-6afd95e5ebb8dd9b37747427)

Thanks, Srinivas. That trace is a good example of why I like asserting on the tool-call sequence as well as the output: an identical call repeated more than a couple of times is cheap to detect and usually means the loop has no new information to act on. Did you end up capping repeats per tool, or comparing arguments between calls to flag it?
