SShortSingh.
Back to feed

Four-layer approach keeps LLM JSON output reliable: schemas, validation, retry, fallback

0
·1 views

A developer guide recommends combining JSON Schema definitions, provider structured-output modes, and code-level validation to get dependable structured data from language models. Schema-constrained decoding fixes the output's shape but not its content, so business rules such as checking for invented numbers or leftover placeholders still need to run in code. When validation fails, the article suggests a single retry with the error message included in the prompt, since repeated attempts mostly add cost and latency. If the output still fails, a deterministic fallback like a template or a review flag gives a predictable result. The author also argues that tracking how often the fallback is triggered is a key health metric for any LLM-powered feature.

Read the full story at DEV Community

This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)

Log in to join the discussion and vote.

Log in

Related stories

0
ProgrammingDEV Community ·

Voice agent evaluators can be less reliable than the agents they grade

Rokas Remeika argues that regex-based scoring in voice agent evaluation pipelines introduces significant noise. Spontaneous speech often omits expected words, causing false negatives, while negated phrasing like "I would not say no" can trigger false refusal flags. These scoring errors can shift aggregate pass rates between evaluation runs even when the agent and model are unchanged. The author proposes a two-tier system that uses strict deterministic matching first, marking uncertain cases as unresolved, and escalates only those to an independent model for adjudication. He suggests practical checks, such as auditing unclassifiable transcripts and rerunning static batches under different scorer versions, to detect this instrument error.

0
ProgrammingDEV Community ·

Filter Toggle Causes 180 ms Interaction Delay and Layout Shift in Catalog Pages

A design-system pull request added a compact-density toggle to a catalog filter bar, but it caused problems on production pages despite working well in local testing. Telemetry showed the 75th-percentile Interaction to Next Paint on mid-tier Android devices rising from 38 ms to 180 ms, while Cumulative Layout Shift spiked to 0.14 as the sticky toolbar moved on each click. Investigation traced the cause to a root CSS variable update, an unstable context value object, and a layout effect that interleaved reads and writes, forcing repeated synchronous layouts. A React.memo hotfix did not help in production. The fix involved wrapping the grid filter update in a transition so the pressed chip could paint before the heavier reconciliation completed.

0
ProgrammingDEV Community ·

Researcher finds Windows 11 build flags coding agent use in optional telemetry

Security researcher Xusheng Li, who works on Binary Ninja, reports that one Windows 11 build keeps a daily yes-or-no flag indicating whether coding agents such as Codex, Claude Code and Copilot were seen running. His findings come from analysis of a single ARM64 virtual machine and Microsoft's documentation, and Microsoft had not commented at the time of reporting. According to Li, the component listens to events Windows already produces and records only which tracked program names appeared, not prompt text or source code. He found the resulting report in a diagnostics upload queue marked as optional, though he observed it being queued rather than leaving the machine. Li also noted that matching relies on executable names, meaning a renamed file could set a flag and a real agent under another name might go uncounted, and that the number of affected PCs is unknown.

0
ProgrammingDEV Community ·

PostgreSQL JSONB Columns Can Cause Heavy Write Amplification Under Frequent Updates

A developer's local benchmark found that incrementing one integer inside a 3.4 KB JSONB column generated about 142 MB of Write-Ahead Log traffic over 20,000 updates, roughly eight times more than updating dedicated scalar columns for the same change. The article attributes this to PostgreSQL's storage mechanics: JSONB values are stored as a single binary object, so any change rewrites the entire value and locks the whole row. Once a JSONB column exceeds the TOAST threshold, even a one-byte change allocates new TOAST chunks, which are written again and logged to WAL, leaving dead tuples behind. Indexing the column with GIN also rules out Heap-Only Tuple updates, forcing new index entries and occasional latency spikes. The author concludes that JSONB suits read-heavy workloads but can strain disk I/O, replication, and VACUUM when frequently mutated.