TL;DR
This paper introduces LegalWiz, a novel framework for generating synthetic legal documents with embedded contradictions. This is crucial for stress-testing AI systems, particularly Retrieval-Augmented Generation (RAG) models, which often struggle with conflicting information in legal texts, leading to unreliable outputs. LegalWiz aims to create more realistic and challenging benchmarks for evaluating AI's ability to detect and handle these legal inconsistencies.
What Problem Does This Paper Address?
Large Language Models (LLMs) are increasingly used in legal applications, but legal documents are inherently complex and often contain contradictions. These contradictions can arise from evolving regulations, overlapping jurisdictions, or competing priorities. When AI systems encounter these conflicts, especially within RAG pipelines that rely on external evidence, they can produce factually incorrect or legally unsound outputs. Existing benchmarks for contradiction detection are often too simplistic, lacking domain realism, covering only limited conflict types, and focusing on single sentences rather than entire documents. This makes it difficult to reliably evaluate and improve AI's performance in high-stakes legal scenarios.
Methods
LegalWiz employs a multi-agent architecture to address these challenges. The system consists of three main agents:
- Content Generator Agent: This agent creates synthetic legal documents that mimic real-world legal tone, structure, and metadata. It supports customizable domains and subdomains and uses a perplexity-based metric to ensure fluency preservation after contradiction injection.
- Contradiction Mining Agent: This agent identifies potential contradictions within the generated documents. It uses a combination of fast semantic filtering (with Sentence-BERT embeddings) and a Natural Language Inference (NLI) model, followed by a more robust LLM (GPT-4o) for judgment. This multi-stage approach balances scalability and reasoning capabilities.
- Retrieval Verifiability Agent: This agent categorizes contradictions as either "retrieval-verifiable" (resolvable with publicly available evidence) or "retrieval-resistant" (requiring reasoning or human judgment beyond retrieval). This distinction helps pinpoint the source of errors in RAG pipelines.
A human-in-the-loop process is integrated throughout for validation, ensuring the realism and accuracy of the generated contradictions and the reliability of the detection benchmarks.
Datasets
The paper introduces a new benchmark dataset constructed around a fictional multinational company, "Aerodyne Systems." This corpus consists of 50 synthetic legal documents spanning five legal domains: contract law, compliance and regulation, internal policy and governance, dispute resolution and litigation, and terms and service management. Contradictions are systematically injected, creating both self-contradictions (within a document) and pairwise contradictions (across documents). The dataset includes 100 self-contradiction pairs and 306 pairwise-contradiction pairs, with a focus on six structured contradiction types (temporal, numerical, authority, process, policy reversal, and specificity).
Key Insights and Ideas
- The Need for Realistic Legal Benchmarks: Simple sentence-pair datasets are insufficient for evaluating AI in legal contexts. Legal documents are complex, and contradictions are often subtle and span multiple documents.
- Controllable Contradiction Generation is Key: To effectively stress-test AI, we need to intentionally inject realistic contradictions that mimic real-world scenarios. This allows for systematic evaluation of detection and resolution capabilities.
- Hybrid Approaches Excel in Contradiction Detection: Combining NLI models (for broad coverage) with LLMs (for deeper reasoning) offers a more robust solution than either method alone, balancing precision and recall.
- Cross-Document Contradictions are Significantly Harder: While AI models are improving at detecting self-contradictions, identifying conflicts across different documents remains a major challenge, likely due to contextual shifts and fragmented evidence.
- Distinguishing Retrieval vs. Reasoning Gaps: The "retrieval-verifiable" vs. "retrieval-resistant" categorization is crucial for diagnosing failures in RAG systems, helping to differentiate between missing information and the need for more advanced reasoning.
Key Results
The LegalWiz framework successfully generated synthetic legal documents with embedded contradictions that were rated highly for fluency, specificity, and coherence by human evaluators.
In contradiction detection experiments, a hybrid NLI+LLM approach achieved the best performance:
- Self-Contradictions: The hybrid model achieved 92.0% accuracy and an F1 score of 89.5%.
- Pairwise Contradictions: The hybrid model achieved 89.5% accuracy and an F1 score of 70.9%.
These results demonstrate that while the hybrid approach significantly improves detection, pairwise contradictions remain substantially more challenging for AI models.
Limitations and Future Work
The authors acknowledge several limitations:
- API Costs: Generating synthetic documents and injecting contradictions can be computationally expensive due to high API costs.
- Synthetic Data: The evaluation relies on synthetic, albeit realistic, documents rather than naturally occurring contradictions, which might limit validation on real-world complexities.
- Human Annotation Dependency: Full automation is not yet possible, as human annotation is required for reliable ground-truth labeling.
Future work includes:
- Expanding the framework into standardized benchmark suites that incorporate both synthetic and real-world contradictions.
- Improving cross-document contradiction detection through retrieval-aware prompting and multi-hop reasoning.
- Systematically testing the performance of different LLMs as context validators.
- Evaluating the robustness of RAG pipelines when presented with conflicting evidence.
Summary updated