<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/how-to-get-reliable-structured-data-out-of-an-llm-lzwbvavpz" -->

---
title: How to Get Reliable Structured Data Out of an LLM
description: A practical deep-dive into extracting reliable structured data from LLM outputs, drawn from building a resume-parsing tool. Covers why prompting alone fails,...
canonical: https://daily.dev/posts/how-to-get-reliable-structured-data-out-of-an-llm-lzwbvavpz
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: How to Get Reliable Structured Data Out of an LLM | daily.dev
og:description: A practical deep-dive into extracting reliable structured data from LLM outputs, drawn from building a resume-parsing tool. Covers why prompting alone fails,...
og:url: https://daily.dev/posts/how-to-get-reliable-structured-data-out-of-an-llm-lzwbvavpz
og:image: https://api.daily.dev/og/posts/lzwbvAVPZ.png
og:image:alt: How to Get Reliable Structured Data Out of an LLM
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# How to Get Reliable Structured Data Out of an LLM

**[freeCodeCamp](https://daily.dev/sources/freecodecamp)** · 20 min read · 0 upvotes · 0 comments

## Summary

A practical deep-dive into extracting reliable structured data from LLM outputs, drawn from building a resume-parsing tool. Covers why prompting alone fails, the three mechanisms for constraining output (JSON mode, tool calling, constrained decoding), designing a Zod schema as the single source of truth, separating syntax/schema/semantic validation, building a cost-aware retry loop with repair requests instead of fresh retries, streaming structured output line-by-line, and identifying failures that retries can't fix (missing data, ambiguity, truncation). Closes with guidance on when this complexity isn't warranted.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.freecodecamp.org/news/how-to-get-reliable-structured-data-out-of-an-llm>

## Questions this post answers

### Should I make LLM extraction schema fields optional or nullable in Zod?

Fields should be nullable rather than optional. An optional field lets a model silently omit a value, making it impossible to distinguish 'the document didn't say' from 'the model forgot.' A nullable field forces the model to make an explicit decision, so null becomes a meaningful, checkable answer instead of a silent gap.

_Anyone hardening an extraction schema against silent LLM omissions can find more patterns like this on daily.dev._

### What is the difference between JSON mode and tool calling for getting structured output from an LLM?

JSON mode only guarantees syntactically valid JSON, with no constraint on keys, types, or structure, so you can still get the wrong shape back. Tool calling forces the model to return arguments matching a JSON Schema attached to a function definition, and with tool_choice set to force that specific tool, providers constrain the output more aggressively than plain JSON mode allows.

_Developers choosing between LLM output constraints can compare tradeoffs like these on daily.dev._

### How can I build a cost-efficient retry loop for LLM JSON extraction failures?

Attempt a cheap local repair first (stripping markdown fences, trimming stray prose around braces) before calling the model again, then send a targeted repair request rather than a fresh attempt: include the original prompt, the failed output, and the specific validation errors. Repairs converge faster and produce shorter outputs than full retries, and capping attempts at three avoids paying for a fourth try that rarely helps.

_Engineers tuning LLM retry strategies to control token spend often track patterns like this on daily.dev._

## Similar posts on daily.dev

- [Structured LLM outputs](https://daily.dev/posts/structured-llm-outputs-teo2nftgk) · Hacker News · 1 upvotes · 0 comments
- [LLM Structured Output with JSON Schema in TypeScript](https://daily.dev/posts/llm-structured-output-with-json-schema-in-typescript-wj1wernyh) · SitePoint · 5 upvotes · 2 comments
- [Your JSON Is Valid but Your Data Is Wrong: Five Failure Modes LLM Structured Outputs Won't Catch](https://daily.dev/posts/your-json-is-valid-but-your-data-is-wrong-five-failure-modes-llm-structured-outputs-won-t-catch-ilmoiq1ob) · Towards Data Science · 1 upvotes · 1 comments
- [Structured Outputs in 2026: A Developer Guide](https://daily.dev/posts/structured-outputs-in-2026-a-developer-guide-4qqi5lmpc) · Alex CloudStar · 1 upvotes · 0 comments
- [Structured Output Reliability at Scale: When JSON Schema Validity Breaks Down Under Concurrency](https://daily.dev/posts/structured-output-reliability-at-scale-when-json-schema-validity-breaks-down-under-concurrency-vhkoljwe3) · DigitalOcean Community · 1 upvotes · 0 comments

---

Tags: [#llm](https://daily.dev/tags/llm), [#typescript](https://daily.dev/tags/typescript), [#anthropic](https://daily.dev/tags/anthropic), [#zod](https://daily.dev/tags/zod)

[View this post on daily.dev](https://daily.dev/posts/how-to-get-reliable-structured-data-out-of-an-llm-lzwbvavpz)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"How to Get Reliable Structured Data Out of an LLM","url":"https://daily.dev/posts/how-to-get-reliable-structured-data-out-of-an-llm-lzwbvavpz","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/how-to-get-reliable-structured-data-out-of-an-llm-lzwbvavpz"},"datePublished":"2026-08-27T22:50:36.120Z","dateModified":"2026-10-15T02:22:58.136Z","description":"A practical deep-dive into extracting reliable structured data from LLM outputs, drawn from building a resume-parsing tool. Covers why prompting alone fails,...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/b1d566cfd5e96ced2791235abc5103d8?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/b1d566cfd5e96ced2791235abc5103d8?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"freeCodeCamp","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"freeCodeCamp","logo":"https://media.daily.dev/image/upload/t_logo,f_auto/v1628412854/logos/freecodecamp","url":"https://daily.dev/sources/freecodecamp"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/how-to-get-reliable-structured-data-out-of-an-llm-lzwbvavpz","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"llm,typescript,anthropic,zod","timeRequired":"PT20M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"freeCodeCamp","item":"https://daily.dev/sources/freecodecamp"},{"@type":"ListItem","position":3,"name":"How to Get Reliable Structured Data Out of an LLM"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/how-to-get-reliable-structured-data-out-of-an-llm-lzwbvavpz#faq","mainEntity":[{"@type":"Question","name":"Should I make LLM extraction schema fields optional or nullable in Zod?","acceptedAnswer":{"@type":"Answer","text":"Fields should be nullable rather than optional. An optional field lets a model silently omit a value, making it impossible to distinguish 'the document didn't say' from 'the model forgot.' A nullable field forces the model to make an explicit decision, so null becomes a meaningful, checkable answer instead of a silent gap. Anyone hardening an extraction schema against silent LLM omissions can find more patterns like this on daily.dev."}},{"@type":"Question","name":"What is the difference between JSON mode and tool calling for getting structured output from an LLM?","acceptedAnswer":{"@type":"Answer","text":"JSON mode only guarantees syntactically valid JSON, with no constraint on keys, types, or structure, so you can still get the wrong shape back. Tool calling forces the model to return arguments matching a JSON Schema attached to a function definition, and with tool_choice set to force that specific tool, providers constrain the output more aggressively than plain JSON mode allows. Developers choosing between LLM output constraints can compare tradeoffs like these on daily.dev."}},{"@type":"Question","name":"How can I build a cost-efficient retry loop for LLM JSON extraction failures?","acceptedAnswer":{"@type":"Answer","text":"Attempt a cheap local repair first (stripping markdown fences, trimming stray prose around braces) before calling the model again, then send a targeted repair request rather than a fresh attempt: include the original prompt, the failed output, and the specific validation errors. Repairs converge faster and produce shorter outputs than full retries, and capping attempts at three avoids paying for a fourth try that rarely helps. Engineers tuning LLM retry strategies to control token spend often track patterns like this on daily.dev."}}]}
```

