Abstract
Navigating the complex, jargon-heavy domain of financial-legal contracts presents significant challenges for standard Large Language Models (LLMs). Researchers at J.P. Morgan AI Research have introduced LAW (Legal Agentic Workflows), a modular framework that utilizes a code-generation agent to orchestrate specialized, reusable tools. LAW addresses common pitfalls such as context window limitations and reasoning failures in multi-hop legal tasks. Experimental results demonstrate that LAW achieves substantial performance gains—up to 92.9% over standard LLM baselines—particularly in complex analytical tasks like calculating contract termination dates.
Introduction
Legal contracts in custody and fund services are characterized by extreme length (averaging 27,000 tokens), lack of structure, and dense terminology. Standard LLM approaches typically struggle with two primary issues: context limits and reasoning failures. Long-context models often suffer from "lost in the middle" retrieval issues when processing multi-document filings. Furthermore, LLMs frequently fail at precise multi-hop reasoning, such as programmatically determining a termination date from disparate clauses.
While fine-tuning a legal-specific LLM is a traditional alternative, it is often prohibitively expensive, difficult to scale, and results in a static system. LAW proposes a shift toward modularity and agentic orchestration to create a more flexible and accurate system.
Methodology: The LAW Framework
The core innovation of LAW is the transition from monolithic model responses to Agentic Workflows. Instead of directly answering a query, the system employs a Code Generation Agent that writes Python code to solve the problem deterministically.
System Architecture
The architecture is built on the FlowMind orchestration framework. As shown in the system diagram, the workflow involves several key components:
- Code Generation Agent: Plans and executes tasks by calling domain-specific tools.
- Specialized Tools: Includes RoBERTa-based extraction for dates, fuzzy matching for legal parties, and a fine-tuned T5-large model for section labeling across 20 legal categories.
- Text Agents: Specialized agents for summarization and comparison that handle long documents via parallel chunk processing.
- Validation Tiers: A three-tier process ensures reliability through syntax validation, hallucination detection, and runtime error handling.
Datasets and Benchmarking
The framework was evaluated using a massive dataset curated from the SEC’s EDGAR database, specifically Form 485BPOS filings. This dataset encompasses 22 GB of data spanning 23 years, totaling 17,831 unique contracts. To benchmark performance, the researchers created a labeled evaluation set of 720 user queries, categorized into "retrieval" (fact-finding) and "analytical" (summarization and comparison) tasks.
Key Results and Insights
LAW significantly outperformed GPT-3.5-turbo baselines across all metrics. A critical insight was that LLMs are more effective at generating code to perform logic than performing the logic themselves.
- Logic and Calculation: In termination date calculations—which require finding an effective date and adding a duration—LAW achieved 95.4% accuracy, whereas the baseline fell to 2.5% due to reasoning failures.
- Extraction Accuracy: LAW reached 100% accuracy in party extraction, compared to 16.3% for the baseline.
- Analytical Depth: For clause summarization, LAW achieved a BERTScore F1 of 89.5, significantly higher than the baseline's 68.1.
Conclusion and Future Work
By prioritizing modularity over monolithic fine-tuning, LAW provides a flexible, up-to-date system where tools can be added or improved independently. Future research will focus on expanding the framework to non-English legal texts and broadening the toolset to other legal domains, such as intellectual property and employment law.
Summary updated