PRODUCTION USE CASE

LLM API for structured data extraction

An operations pipeline extracts supplier, invoice number, currency, total, tax, and due date from emailed invoices. Gemini 2.5 Flash receives OCR text plus layout hints and must return one versioned JSON object.

Document fields transformed into schema-validated JSON
LLM API for structured data extraction

Production recipe

API, primary model, and failover configuration

Production choiceRecommendationWhy
APIPOST /v1/chat/completionsOpenAI-compatible server-side request
Primary modelgemini-2.5-flashGemini 2.5 Flash is the primary high-throughput extraction route in the current catalog.
Fallback modelgpt-5.4-miniUse gpt-5.4-mini when it performs better on a specific document family. Escalate long or layout-heavy documents to Gemini 2.5 Pro.
Escalation modelgemini-2.5-proUse only when the primary route fails the defined quality or complexity boundary
Output contractValidated JSONStrict invoice.v3 JSON with typed fields, nulls for missing data, and a source span per value.
01
Scenario

Structured data extraction in a production application

An operations pipeline extracts supplier, invoice number, currency, total, tax, and due date from emailed invoices. Gemini 2.5 Flash receives OCR text plus layout hints and must return one versioned JSON object.

Missing fields remain null. Ambiguous totals include candidate values and source spans. The pipeline validates types and arithmetic before accepting the record; failures go to repair or review.

02
Architecture

How the structured data extraction workflow operates

  • OCR and preserve source spans.
  • Send the schema version with the document.
  • Request strict JSON with null for absent data.
  • Validate schema, currency, totals, dates, and evidence spans.
  • Accept, repair once, or route to human review.
03
API request

Call gemini-2.5-flash through LLMFly AI

Send the request from your server. Replace the example content and placeholder tool schema with data and tools from your application.

request.exampleCopy-ready
curl https://app.llmfly.ai/v1/chat/completions \
  -H "Authorization: Bearer $LLMFLY_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "gemini-2.5-flash",
    "messages": [
      {"role": "system", "content": "Extract one invoice into the supplied JSON schema. Use null for absent fields. Include a source span for every non-null value. Never guess."},
      {"role": "user", "content": "Extract this invoice using schema invoice.v3."}
    ],
    "response_format": {"type": "json_object"}
  }'
04
Model choice

Why gemini-2.5-flash is the primary model

Gemini 2.5 Flash is the primary high-throughput extraction route in the current catalog.

Use gpt-5.4-mini when it performs better on a specific document family. Escalate long or layout-heavy documents to Gemini 2.5 Pro.

05
Acceptance

Acceptance checks for structured data extraction

MetricPass condition
Schema-valid response rateThe response validates against the versioned schema without repair
Precision and recall by fieldEach critical field meets its separately defined precision and recall target
Unsupported-value rateEvery value has a supporting source span or explicit derived-value rule
Cost per accepted recordGeneration, validation, repair, and review stay within the processing budget
06
Failure handling

Failures to handle before deployment

  • Treating valid JSON as correct data
  • Guessing missing fields
  • Changing schemas without versions
  • Averaging away critical errors
07
Output

Returned output and run records

Strict invoice.v3 JSON with typed fields, nulls for missing data, and a source span per value.

Record the model ID, request ID, token usage, retries, validation result, and final disposition for every production run.

Frequently asked questions

Is valid JSON enough?

No. Validate the schema, then compare every extracted value with source evidence.

How should missing values be represented?

Define the contract, such as null for absent data and a separate status for ambiguity.

Which metric matters most?

Report precision and recall per field, especially for fields that trigger actions.

Test this setup with your own inputs

Compare the primary and fallback models with the same requests, tools, and validation rules.

Compare models