TL;DR:
- AI agents excel at specific contract review subtasks: clause identification, obligation extraction, deviation flagging against a playbook, and cross-document comparison
- The most effective architectures separate extraction (structured output from LLM) from reasoning (agent deciding what matters) from presentation (report or redline)
- Human-in-the-loop at the final stage is not optional — AI agents reduce review time, not attorney accountability
Legal document processing is one of the highest-value applications of AI agents that doesn’t require a consumer product or complex integrations. The raw workflow is straightforward: a document goes in, structured analysis comes out. But building that workflow to be reliable enough for professional use is where most teams run into trouble.
This guide covers the architectures that work in production, where the common failure modes are, and which tools have become the go-to stack.
What AI Agents Actually Do Well in Legal Workflows
Contract review involves tasks at different levels of complexity. Some are well-suited to current AI agents; others still require human judgment.
Well-suited tasks:
- Clause identification and categorisation (what type of clause is this? Indemnity, limitation of liability, governing law?)
- Deviation detection against a standard playbook (is this clause materially different from our standard position?)
- Obligation extraction (what are the deadlines, recurring commitments, and trigger conditions in this agreement?)
- Defined term tracking (find every use of “Confidential Information” and flag definitions that don’t match)
- Cross-document comparison (how does version 3 differ from version 2 on indemnification?)
- Missing clause detection (this agreement has no force majeure provision)
Not well-suited (yet):
- Strategic negotiation advice requiring full business context
- Predicting how a court would interpret an ambiguous clause
- Novel risk assessment with no playbook precedent
Being explicit about this boundary is important. Scope creep in legal AI projects tends to inflate expectations and set up hard-to-recover-from trust problems when edge cases surface.
Architecture: Three Layers
The most reliable production architectures have three distinct layers:
Layer 1: Document ingestion and chunking. PDFs, DOCX, and scanned images all need different treatment. For text PDFs, direct extraction works well. For DOCX, parsing the XML directly (via python-docx or similar) preserves clause structure better than converting to plain text. For scanned documents, a vision model or OCR step is required. Chunking by clause or section rather than by token count significantly improves extraction accuracy — clause boundaries are meaningful structure.
Layer 2: Structured extraction. An LLM with a defined JSON schema extracts clauses, identifies their type, and pulls out key terms. Pydantic models with field-level descriptions work well here. The extraction step should be dumb and comprehensive — pull everything; let the agent decide what matters. Validation at this layer catches hallucinated clause types before they propagate.
Layer 3: Reasoning and comparison. The agent runs the extraction output against a playbook (typically a set of standard clause positions stored in a vector database for fuzzy matching). It identifies deviations, assigns severity, and produces a structured risk assessment. This is where LangGraph, PydanticAI, or a similar stateful framework is useful — the agent needs to track state across multiple clauses and make holistic judgments (e.g., a non-standard limitation of liability clause interacts with an unusually broad indemnification clause).
Tool Stack
Document processing: pypdf for text PDFs, python-docx for Word documents, unstructured for mixed content types. For scanned contracts, Mistral OCR or AWS Textract.
LLM for extraction: Claude Sonnet or GPT-4o. Structured output via tool calling with a defined schema. Structured outputs from major providers have become reliable enough for production extraction workflows — JSON mode is adequate for simple schemas, tool calling for complex nested structures.
Playbook storage: A vector database (Qdrant, Weaviate, or pgvector) storing your standard clause positions. Semantic search finds the closest standard clause to what’s in the document. Exact matching alone doesn’t work because clause language varies too much.
Orchestration: LangGraph works well for multi-clause review workflows where state needs to persist across clause comparisons. For simpler single-document review, a PydanticAI agent with structured outputs is lower overhead.
Output: For internal review, a JSON report that maps to a structured template. For lawyer-facing output, a Word document with comments attached to specific clauses (using python-docx comment insertion) is often more useful than a separate report.
Common Failure Modes
Playbook drift. Standard clause positions change. If the vector database isn’t updated when the standard playbook changes, the agent flags clauses as non-standard that are actually fine. Version control your playbook.
PDF structure problems. Multi-column PDFs, watermarked documents, and PDFs where the text layer doesn’t match visual layout all produce bad extraction. Build a validation step that checks extraction quality before sending to the agent.
Context window limits on long agreements. A 60-page master services agreement with exhibits doesn’t fit in context. Use a hierarchical approach: summarise each section first, then reason across sections. Clause-level chunking helps, but the agent needs enough context to understand what a clause refers to.
False confidence in deviation flagging. LLMs will flag a clause as non-standard even when they’re not sure. Add a confidence field to extraction outputs and threshold what gets escalated to human review. Low-confidence flags that look like high-severity deviations are a common source of trust erosion.
A Practical Starting Point
If you’re building from scratch, start narrow. Pick one document type (NDAs are a good starting point — short, standard structure, well-understood risk surface) and build the full pipeline for that type before expanding. An NDA review agent that reliably identifies the 12 clauses that matter in an NDA is more useful than a general contract agent that handles all types poorly.
The tools that have made this more accessible in 2026: Anthropic’s tool use with structured outputs, LangGraph for stateful multi-step review, and unstructured for handling diverse document formats without per-format code. The remaining hard part is building and maintaining the playbook that defines what “correct” looks like — that’s institutional knowledge, not an AI problem.
Further Reading
- LangGraph documentation on stateful agent workflows
- Anthropic’s tool use documentation for structured extraction
unstructuredlibrary for document ingestion- PydanticAI framework for typed agent outputs