Skip to content
ML Academy

LLMs, GenAI, RAG, agents, evaluation · insight-0531

Extract from long documents section by section with provenance, then aggregate in code

Evidence type
practitioner heuristic
Difficulty
medium
Roles
Applied AI, Data analyst
Industries
logistics, aviation

Summary: situation, action, reason, boundary

  1. Situation

    An analyst asks a model to list every penalty clause from a long supplier contract in one call.

  2. Action

    Split the document into sections, extract per section into a schema that includes the page or section reference, then deduplicate, merge and count in code; spot-check a sample against the source.

  3. Reason

    Smaller inputs reduce long-context position effects, and provenance fields make every extracted item checkable.

  4. Boundary

    Contracts, regulatory filings, policy manuals, long reports.

Symptom or risk

Clauses in the middle are missed, duplicates appear, and nobody can trace an extracted clause back to its page.

Exceptions

Facts that span sections, such as a definition used later, need context passed between steps.

Trade-offs

More calls and orchestration; cross-section reasoning becomes harder.

Pitfalls

Letting the model do the final aggregation and counting, which code does exactly.

Lessons and concepts

Claims and their sources