LAW: Legal Agentic Workflows for Custody and Fund Services Contracts

William Watson, Nicole Cho, Nishan Srishankar, Zhen Zeng, Lucas Cecchi, Daniel Scott, Suchetha Siddagangappa, Rachneet Kaur, Tucker Balch, Manuela Veloso

TL;DR

Researchers at J.P. Morgan AI Research have introduced LAW (Legal Agentic Workflows), a modular framework that uses a code-generation agent to orchestrate specialized tools for analyzing complex legal contracts. By moving away from expensive fine-tuning toward a tool-use approach, LAW achieves massive performance gains—surpassing standard LLM baselines by up to 92.9% on complex reasoning tasks like calculating contract termination dates.

What Problem Does This Paper Address?

Legal contracts in the financial domain (specifically custody and fund services) are a nightmare for standard AI. They are incredibly long (averaging 27,000 tokens), highly unstructured, and packed with dense jargon.

Off-the-shelf Large Language Models (LLMs) like GPT-3.5 or GPT-4 often fail here because their context windows are too small to "read" the whole document at once, and they frequently hallucinate specific details like dates or parties. While some researchers try to solve this by fine-tuning models on legal text, the authors argue this is a "static" solution: it’s expensive, hard to scale, and the model quickly becomes outdated as new regulations or contract types emerge.

Methods

Instead of building a better "legal brain" through fine-tuning, the authors built a better "legal workstation." LAW uses a modular, agentic architecture:

  1. The Orchestrator: A Code Generation Agent that receives a user query and writes Python code to solve it. This code acts as the "plan," calling various specialized tools in sequence.
  2. Domain-Specific Tools:
    • Extraction Tools: Use RoBERTa and fuzzy matching to pull out specific dates and parties.
  3. Reasoning Tools: Calculate contract lifecycles (e.g., adding a 3-year duration to an effective date) or identify "Master" vs. "Amendment" agreements.
  4. Semantic Labeling: A fine-tuned T5 model classifies paragraphs into 20 distinct legal sections (like "indemnification" or "termination") to enable precise retrieval.
  5. Text Agents: Specialized agents for summarization and comparison. To handle documents that exceed context limits, LAW splits text into chunks, processes them in parallel via "sub-agents," and then concatenates the results.
  6. Validation Loop: A three-tier system checks the generated code for syntax errors, "hallucinated" tools that don't exist, and runtime failures, providing feedback to the agent to self-correct.
Figure 1: Comparing the traditional method of fine-tuning a legal LLM vs. LAW (Legal Agentic Workflows). Fine-tuning involves labeling contracts for a highly customized pipeline supported by open-source LLMs, which results in limited context, scale, or flexibility where coaxing additional information out of the model would require further tuning. The ensuing prompt engineering on the fine-tuned legal LLM also exacerbates the model’s loss of generality. In contrast, LAW can operate on both closed-source or open-source LLMs and is equipped with legal domain-specific tools. These tools are cheaper to construct, reusable, simpler to construct, and incorporates recent data. The general LLM’s orchestration of these tools along with the text agents engenders LAW, a highly interactive agentic system that also enables the addition of more tools and agents.

Datasets

The researchers focused on Form 485BPOS, a regulatory filing for investment companies governed by the US Investment Company Act of 1940.

  • Source: The SEC’s EDGAR database.
  • Scale: 23 years of filings, resulting in a knowledge base of 17,831 legal contracts (approx. 22 GB of data).
  • Evaluation: A curated dataset of 720 labeled user queries, ranging from simple retrieval (finding parties) to complex analytical tasks (comparing clauses across time).

Key Insights and Ideas

  • Code as the "Glue": Using an LLM to generate Python code to solve a problem is far more reliable than asking the LLM to generate the answer directly. Code provides a deterministic way to handle math (like date calculations) and data manipulation.
  • Modularity over Monoliths: By using a suite of reusable tools, the system is "future-proof." If a new type of contract appears, you only need to add a new tool or update a specific agent, rather than retraining the entire model.
  • The Context Gap: Standard RAG (Retrieval-Augmented Generation) often fails on legal docs because relevant information is scattered. LAW’s "multi-doc traversing" and parallel sub-agents allow it to maintain a "global" understanding of documents that are hundreds of pages long.
Figure 2: System Overview of LAW. (1) User query input on front-end (§6); (2) Query manipulation and custom modification added to prompt and sent to the code generation agent (§6); (3) Chat completion return from the code generation agent; (4) Execution of backend API tools (§4); (5) Tool retrieval of information from internal cache (§6); (6) Calls to text agents (§5); (7) Calls to multi-node OpenSearch cluster for text retrieval (§6); (8) Feedback on code runs back to the code generation agent in case of failure; (9) Concatenation of final output; (10) Final text output is rendered on the UI; (11) EDGAR contracts undergo continuous, offline, distributed processing to update our internal cache and OpenSearch systems (§3).

Key Results

The performance gap between LAW and a GPT-3.5-based RAG baseline is stark, particularly as task complexity increases:

  • Multi-Hop Reasoning: On the task "Find termination dates" (which requires finding an effective date and a duration, then doing the math), LAW achieved 95.4% accuracy, while the baseline managed only 2.5%.
  • Entity Extraction: LAW hit 100% accuracy in identifying parties, compared to the baseline's 16.3%, which often missed entities in dense text.
  • Analytical Tasks: For comparing clauses across different contracts, the baseline often failed entirely due to context limits, while LAW maintained high performance (71.9 BERTScore F1).
Quantitative comparison of LAW vs. Baseline

Limitations and Future Work

While LAW is highly effective, the authors note a few hurdles:

  • Tool Reliability: The system is only as good as its tools. Ensuring tools work across every possible weirdly-formatted contract remains a challenge.
  • Orchestration Complexity: As more tools are added, the logic required for the agent to choose the right tool becomes more complex.
  • Language: The current system is optimized for English-language contracts.

Future work will look into expanding LAW to non-English contracts and exploring how these agentic workflows can be applied to other specialized domains like medicine or engineering.

Summary updated

BibTeX
@inproceedings{watson2025law,
  author = {William Watson and Nicole Cho and Nishan Srishankar and Zhen Zeng and Lucas Cecchi and Daniel Scott and Suchetha Siddagangappa and Rachneet Kaur and Tucker Balch and Manuela Veloso},
  title = {{LAW: Legal Agentic Workflows for Custody and Fund Services Contracts}},
  booktitle = {International Conference on Computational Linguistics},
  year = {2025},
}
Figure