All Lessons

A fintech company is building an AI that extracts invoice data (vendor name, invoice date, total amount, line items) from PDF invoices. The downstream payment system requires strict JSON output with exactly these fields. The team tried asking the model to output JSON, but the model occasionally adds fields like currency or tax_rate, causing the pipeline to reject the output. What is the best way to ensure the model outputs valid JSON matching the exact schema?

1 / 3
intermediate 20 min

JSON Mode

Loading lesson content...

An e-commerce platform uses Claude to generate product metadata for 10,000 products daily. Each product needs JSON with title, price, category, and tags array. JSON mode works but 3-5% of products have incorrect categories - a running shoe categorized as Electronics instead of Footwear. The team needs to fix this without slowing the batch pipeline. What approach best addresses incorrect semantic content within valid JSON?

1 / 2

A parser downstream of JSON mode often fails because Claude outputs comments within JSON (which is not valid JSON). What's the fix?

1 / 2