PRODUCTION USE CASE

LLM API for document analysis

A legal operations team compares a master services agreement with a security addendum and pricing schedule. The parser preserves page numbers, headings, tables, and footnotes. The model receives selected sections and produces a clause-by-clause deviation report.

Long document analysis with cited evidence and structured findings
LLM API for document analysis

Production recipe

API, primary model, and failover configuration

Production choiceRecommendationWhy
APIPOST /v1/chat/completionsOpenAI-compatible server-side request
Primary modelgemini-2.5-proGemini 2.5 Pro is the first route for large mixed document sets and cross-document comparison.
Fallback modelgpt-5.6-terraUse Terra for text-only sets already reduced to the relevant sections. Escalate only the unresolved high-risk clauses to Sol or counsel.
Escalation modelgpt-5.6-solUse only when the primary route fails the defined quality or complexity boundary
Output contractValidated JSONA clause-level deviation table with document and page citations for every row.
01
Scenario

Document analysis in a production application

A legal operations team compares a master services agreement with a security addendum and pricing schedule. The parser preserves page numbers, headings, tables, and footnotes. The model receives selected sections and produces a clause-by-clause deviation report.

Every deviation must cite the exact document and page. OCR confidence is checked before the model call; a bad scan is reprocessed instead of asking the model to guess.

02
Architecture

How the document analysis workflow operates

  • Parse documents while preserving page and structural references.
  • Select clauses relevant to the review question.
  • Ask for a normalized deviation table.
  • Verify every citation against the source span.
  • Route missing, conflicting, or low-OCR evidence to review.
03
API request

Call gemini-2.5-pro 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-pro",
    "messages": [
      {"role": "system", "content": "Compare the supplied contract sections. Return a deviation table with issue, baseline clause, changed clause, risk, document ID, and page. Never infer missing text."},
      {"role": "user", "content": "Compare liability, security, renewal, and pricing terms across these documents."}
    ],
    "response_format": {"type": "json_object"}
  }'
04
Model choice

Why gemini-2.5-pro is the primary model

Gemini 2.5 Pro is the first route for large mixed document sets and cross-document comparison.

Use Terra for text-only sets already reduced to the relevant sections. Escalate only the unresolved high-risk clauses to Sol or counsel.

05
Acceptance

Acceptance checks for document analysis

MetricPass condition
Evidence accuracyEvery material answer points to the correct page, section, table, or footnote
Cross-section recallCross-section questions include all necessary supporting passages
Table and footnote handlingValues and qualifications in tables and footnotes survive parsing correctly
Cost per documentParsing, retrieval, generation, and verification stay within the per-document budget
06
Failure handling

Failures to handle before deployment

  • Assuming large context removes retrieval
  • Losing page references
  • Scoring fluent but unsupported summaries
  • Ignoring malformed pages
07
Output

Returned output and run records

A clause-level deviation table with document and page citations for every row.

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

Frequently asked questions

Should the whole document go in one prompt?

Only when the tested route, task, latency, and cost support it; retrieval often still helps.

How can answers be audited?

Preserve page identifiers and require material answers to point to supporting passages.

How should scanned PDFs be handled?

Evaluate OCR quality separately before judging the language model.

Test this setup with your own inputs

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

Compare models