
Teammately
Official

Legal Contract Analyzer
About this AI
Summary
This AI project, Legal Text Structuring and Analysis, aims to streamline legal document analysis for professionals by transforming unstructured contract text into structured, organized data. By utilizing large language models (LLMs), this AI-Agent is designed to extract valuable information from legal contracts, such as summaries, key clauses, risks, obligations, and compliance checks. The solution is delivered through an API, enabling seamless integration into existing legal platforms to enhance their analytical capabilities. This ensures both efficiency and accuracy in legal contract analysis, reducing the manual workload and enabling legal teams to focus on strategic decision-making.
Major Use Cases
Contract Summary: Generate summary from a complete legal contract.
Clause Extraction: Extract specific clauses like termination from legal documents.
Risk Identification: Identify potential risks or liabilities in contracts.
Obligation Tracking: Highlight contractual obligations in contract agreements.
Compliance Check: Verify legal compliance of contract terms.
Milestone
Project Requirements Definition: We have formulated a thorough PRD to define the objectives, features, and use-case scenarios for the AI-Agent.
AI Development: We have developed the AI system to process legal contracts and generate structured outputs using LLMs.
Testing and Validation: We have established testing frameworks and conducted quick tests to ensure the system's performance and accuracy.
API Deployment: We have compiled the AI into an API for seamless integration into existing legal systems.
AI Architecture & Logic Plans
AI Plans
API INPUT KEYS
contract_textText
STEPS
Generate Structured Summary
Model
openai / gpt-4oPrompt
[Overview] The task is to generate a structured summary from a legal contract provided in text form. The purpose is to extract and highlight the key elements and general themes present within the document, ensuring it is both coherent and concise for an efficient review process by legal professionals.
[Objective] Create a clear and precise summary that encapsulates the essence of the contract, elucidating main points such as parties involved, duration, obligations, and any critical clauses or conditions mentioned.
[Guidelines]
- Use concise language to capture essential information while avoiding superfluous details.
- Maintain coherence throughout the summary, ensuring that it flows logically and is easy to understand.
- Integrate legal terminology appropriately to reflect the content accurately.
- Provide a brief overview of the contract's significant aspects and themes.
## Input
- Contract Text: {{contract_text}}Value of the API input "contract_text" is inserted
## Output Format
- JSON Object:
```json
{
"summary": "concise summary text"
}
```
Example:
```json
{
"summary": "This contract is between ABC Corp and XYZ LLC, lasting three years, detailing obligations on marketing agreements and termination conditions."
}
## Output
- Do not include any unnecessary prefixes or annotations.
Extract Key Clauses
Model
openai / gpt-4oPrompt
## Task: Extract Key Clauses from Contract
### Instructions
You are tasked with extracting specific legal clauses from a given contract. Focus particularly on identifying and extracting termination clauses. Use advanced understanding of legal terminology and context to ensure accuracy and relevance.
### Input
Contract Text:
{{contract_text}}Value of the API input "contract_text" is inserted
### Requirements
- Clearly identify and extract key clauses, such as termination clauses.
- Use the structured output format provided.
- Ensure no unnecessary explanation or prefix is included in the output.
### Output Format
```json
{
"clauses": [
{
"type": "<clause type>",
"content": "<clause content>"
}
]
}
```
### Example
Example 1:
Contract Text:
"Tenant shall have the right to terminate this lease upon..."
Expected Output:
```json
{
"clauses": [
{
"type": "termination",
"content": "Tenant shall have the right to terminate this lease upon..."
}
]
}
```
## Output
Identify Risks
Model
openai / gpt-4oPrompt
Role Definition:
You are a legal advisor proficient in contract analysis, tasked with identifying potential risks and liabilities in legal documents.
Task Specification:
Examine the legal contract text provided, focusing on identifying risks related to indemnity clauses, limitations of liability, warranties, and penalties. Demonstrate understanding of nuanced legal language and context that indicate these risks.
Input:
Contract text: {{M2WwLeqfR0mQpLpQTlriOg}}Value of the result from the step "Generate Structured Summary" is inserted
Examples for Guidance:
1. Example Contract Snippet: "The supplier shall not be liable for any indirect damages."
Identified Risk: Limitation of liability affecting damage claims.
2. Example Contract Snippet: "The customer shall indemnify the provider against all claims."
Identified Risk: Indemnity clause increasing customer liability.
Output:
Generate a structured list of identified risks in JSON format without any unnecessary prefixes.
Example Output:
{
"risks": [
"Limitation of liability affecting damage claims.",
"Indemnity clause increasing customer liability."
]
}
Response:
Ensure clarity and precision by using concise sentences.
Track Obligations
Model
openai / gpt-4oPrompt
System: You are a language model specialized in legal contract analysis, particularly skilled in identifying contractual obligations.
Introduction: This module focuses on identifying contractual duties within legal contracts to aid legal professionals in tracking obligations.
Objective: To accurately track obligations within legal contracts by analyzing the substance and context of the contract text. This involves recognizing and extracting clear duty statements and nuanced language that suggest responsibilities.
Context: Below you will find a structured summary and extracted key clauses from a legal contract to assist you in identifying obligations.
Summary:
{{M2WwLeqfR0mQpLpQTlriOg}}Value of the result from the step "Generate Structured Summary" is inserted
Key Clauses:
{{rQFsjvB1Rd2qtDoDk_gtNw}}Value of the result from the step "Extract Key Clauses" is inserted
## Task Description
1. Analyze the provided legal contract context.
2. Identify and list all contractual obligations.
3. Ensure thorough coverage of potential duties, especially those implied through nuanced language.
## Examples
Example Contract Text: "The lessee shall maintain the premises in good repair."
Extracted Obligations: ["Maintain the premises in good repair"]
Example Contract Text: "The seller agrees to deliver the goods by the specified date."
Extracted Obligations: ["Deliver the goods by the specified date"]
## Output Format
- Please provide the extracted obligations as a JSON array.
Response:
Extracted obligations: [{"obligations": ["Obligation1", "Obligation2"]}]
Note: Do not include any unnecessary prefixes or suffixes in your response.
API OUTPUT KEYS
summaryGenerate Structured SummaryText
clausesExtract Key ClausesText
risksIdentify RisksText
obligationsTrack ObligationsText
Here are several examples of the input and output of this model.
Quick Test
Input
AI Synthesized
contract_text
Run
4 steps12,286 ms
Output
from your model in draft
clauses
```json
{
"clauses": [
{
"type": "termination",
"content": "Either party may terminate the agreement with a 30-day written notice."
}
]
}
```
obligations
Extracted obligations: [{"obligations": ["Deliver monthly service reports by the 15th", "Report discrepancies within 7 business days", "Provide 30 days' written notice to terminate the agreement"]}]
risks
{
"risks": [
"Potential liability due to lack of specific indemnity clause terms.",
"Absence of explicit limitation of liability provisions may lead to unrestricted damage claims.",
"No detailed warranty terms, which could result in dispute over service quality.",
"Vague penalty terms for failure to deliver monthly service reports may result in enforcement issues."
]
}
summary
```json
{
"summary": "The Service Agreement, effective August 1, 2023, is between Tech Solutions Inc. ('Provider') and Greenfield Farms Ltd. ('Customer'). The Provider must deliver monthly service reports by the 15th. The Customer has 7 business days to report discrepancies. Either party can terminate the agreement with 30 days' written notice."
}
```
Quick Evaluation by LLM Judges
Metric
Interpretation Accuracy of Legal Terminology
Score
Reason
The model demonstrates a partial understanding of legal terminology. While it correctly identifies a termination clause ("Either party may terminate the agreement with a 30-day written notice"), the risk assessment section contains inaccuracies and omissions. For example, the model identifies potential risks related to lack of indemnity and liability limitations, but the identified risks are not directly supported by the provided contract text. The summary is accurate, but the obligations section is incomplete and lacks precision. The model shows some ability to interpret legal terms, but inconsistencies and inaccuracies exist, indicating a partial understanding rather than a complete grasp of the nuances of legal terminology. Expand
Metric
Validation Consistency across Contract Types
Score
Reason
The model demonstrates consistent extraction of key information (summary, clauses, risks, obligations) from the provided contract text. The response accurately identifies the parties, effective date, key obligations (reporting deadlines, termination clauses), and potential risks. The JSON structure is correctly formatted and adheres to the specified output format. No inconsistencies or inaccuracies are observed in the extraction process across the different elements, meeting the criteria for a Grade 2. Expand
Metric
Extraction Precision
Score
Reason
The model accurately extracts key data points from the contract, including dates, parties, obligations, and termination clauses. The JSON output adheres to the expected structure and accurately represents the contract's content. For example, the "obligations" section correctly identifies the monthly report delivery, discrepancy reporting, and termination notice requirements. The "clauses" section correctly identifies the termination clause. The "summary" section provides a concise summary of the agreement. No inaccuracies or omissions are present in the extracted data. Expand
Evaluation Results
Evaluation Report
Introduction
Evaluation target plan
[ContractPro: Legal Text Structuring and Analysis](/genflows/l9ZRuhDCTHGEO-HUy6_3dw/develop/cUiHFV9yTR2Djzhx2JBvtA)
Datasets to test this AI model
We've prepared 50 cases from 5 major use cases, generated by LLM Dataset Synthesizer, like
Contract Summary Generate summary from a complete legal contract.
Clause Extraction Extract specific clauses like termination from legal documents.
Risk Identification Identify potential risks or liabilities in contracts.
Obligation Tracking Highlight contractual obligations in contract agreements.
Compliance Check Verify legal compliance of contract terms.
LLM Judge
We've simulated this AI from the prepared test datasets and analyzed the response by LLM Judges.
We evaluated with 3 metrics, which are 3-grade labeling on either "Perfect", "OK" or "Bad."
The LLM Judges used are as follows:
Extraction Precision: Accurately extracts all specified information from legal contracts, adhering to the PRD specifications and demonstrating precise identification and representation of key data elements in the JSON output.
Validation Consistency across Contract Types: Demonstrates consistent and reliable validation across diverse contract types, ensuring high reliability as specified in the metric description.
Interpretation Accuracy of Legal Terminology: Reflects a strong understanding of legal terms and their contextual meaning within contracts, addressing the nuances of legal language across all use cases.
Evaluation Results
Performance
The AI showed a high level of accuracy, particularly in the Validation Consistency metric, achieving perfect performance across all test cases. This is illustrated in the chart below, affirming the model's reliable behavior in handling contract variations.
Overall Metric Performance
However, there's room for improvement in Interpretation Accuracy of Legal Terminology. While still achieving a
94.3%
perfect score, the 5.7%
classified as "OK" suggests that certain legal terms may not be fully understood, potentially affecting nuanced contract interpretations.In use-case specific performance, Contract Summary and Compliance Checks maintained a consistent high score of
2.0
across all metrics, indicating robust handling of these tasks.On the other hand, Risk Identification showed relative weakness in the Interpretation Accuracy of Legal Terminology with an average score of
1.3
, pointing to challenges in accurately assessing legal risks.Use Case Specific Performance
Overall, while the AI excels in most areas, focusing enhancements on interpretation, especially for complex legal terms, and improving task-specific weaknesses like Risk Identification will further solidify its utility and reliability for legal professionals.
Potential Hallucinations & Common Error Patterns
The AI system has demonstrated some limitations in interpreting specific legal terminologies, as highlighted in the failed case where the input
contract_text
included a purported termination clause: "This clauS may b interpreted Multifacetedly, leaving neither out wrongly termination as it suits ones cause without resolve."
The AI output successfully flagged risks and clauses related to ambiguity, but lacked granularity in distinguishing between terms like "wrongful termination" and "breach of contract." This indicates a tendency to miss nuanced differences in legal context, affecting its "Interpretation Accuracy of Legal Terminology."The system is prone to omitting detailed
obligations
from its output. In the reported case, it returned "Extracted obligations: [{\"obligations\": []}]"
, causing a gap in comprehension of the document's binding commitments. Such omissions reflect a need for improved extraction algorithms, capable of capturing all relevant obligations, without overlooking critical aspects.There is room for enhancement in the AI's summarization capability as seen from the same test case. Though the
summary
flagged ambiguity, the level of elaboration and precision was limited. Incorporating structured details and specificity could elevate the utility of summaries, aligning outputs more closely with user intent and satisfying context comprehension requirements. This demonstrates an overarching need for refining contextual understanding and interpretation capabilities.Conclusions
Is this model production ready?
Almost ready, given the evaluation results. The AI model showed a high accuracy in Validation Consistency with perfect scores across all test cases, indicating readiness for diverse contract handling. However, Interpretation Accuracy of Legal Terminology indicated some minor weaknesses with a
94.3%
perfect score, leaving 5.7%
classified as "OK." Additionally, the AI's weakest performance was in Risk Identification with an Interpretation Accuracy average score of 1.3
. This indicates that while the model is quite proficient, it requires further refinement in understanding complex legal terminologies in specific contexts.In general, the "Bad" records show a margin low enough to push this system closer to production-ready status. Yet, continuous monitoring and validation with unexpected inputs are essential to ensure that the quality and accuracy of the AI remain high.
Future Improvements
Enhancement in Legal Terminology Interpretation: Focus on refining the AI's understanding of nuanced legal language, which could involve further training using a more extensive dataset of varied contracts. Developing dedicated modules for specific legal terms, especially ambiguous or multifaceted terminologies, can help improve the interpretation of complex clauses.
Improvement in Risk Identification Accuracy: As Risk Identification showed relative weakness, targeted improvements could include the integration of legal risk databases and expert-reviewed risk scenarios to fortify this use case. Enhanced context recognition, possibly through AI retraining with focus on contextually rich scenarios, can help in making more accurate legal assessments.
Integration
How this model is served
This AI model is deployed at the endpoint
https://tmmt.ly/:id
and is accessible via the Teammately API. It facilitates the extraction of structured information from legal contracts by processing the contract text into JSON formatted data.Integration Example
For the use case of Contract Summary and Clause Extraction within a Python environment, follow the steps below to integrate the AI into your project.
1.Contract Summary and Clause Extraction
python
import requests
api_url = 'https://tmmt.ly/:id'
headers = {
'Authorization': 'Bearer YOUR_TEAMMATELY_API_KEY',
'Content-Type': 'application/json'
}
contract_text = """[Insert your legal contract text here as a UTF-8 encoded string]"""
data = {
'input': {'text': contract_text}
}
response = requests.post(api_url, headers=headers, json=data)
response_data = response.json()
summary = response_data.get('summary')
clauses = response_data.get('clauses')
print("Contract Summary:", summary)
print("Extracted Clauses:", clauses)
For the use case of Risk Identification and Obligation Tracking using JavaScript in a Node.js environment, you can follow this integration pattern:
1.Risk Identification and Obligation Tracking
javascript
const axios = require('axios');
const apiUrl = 'https://tmmt.ly/:id';
const apiKey = 'YOUR_TEAMMATELY_API_KEY';
const contractText = '[Insert your legal contract text here as a UTF-8 encoded string]';
axios.post(apiUrl, {
input: { text: contractText }
}, {
headers: {
'Authorization': `Bearer ${apiKey}`,
'Content-Type': 'application/json'
}
})
.then(response => {
const { risks, obligations } = response.data;
console.log('Identified Risks:', risks);
console.log('Tracked Obligations:', obligations);
})
.catch(error => {
console.error('Error during API call:', error);
});
Frontend Example
Frontend Example
Next: How to improve more?
Evaluation and Testing:
The AI model has gone through rigorous testing, yet it is crucial to continuously assess its performance. We recommend running the model with hundreds of diverse test cases to ensure readiness for production deployment. Doing so will uncover edge cases that may have been missed in initial evaluations. Teammately Agents can assist by synthesizing these test cases and generating tailored LLM Judges to facilitate evaluation at scale.
Integration with Knowledge Bases:
To enhance the AI’s accuracy and contextual understanding, consider integrating it with comprehensive knowledge bases. For example, linking the AI with domain-specific databases can improve its ability to process and respond to specialized queries. Exploring platforms like Wolfram Alpha or specialized industry databases could provide substantial benefits depending on the use case.
Cost and Latency Optimization:
While the current model delivers satisfactory results, exploring smaller, more efficient models can reduce operational costs and improve response times. Teammately Agents are capable of iterating on these experiments, maintaining quality with continuous evaluations by LLM Judges. This iterative approach allows for balancing performance with resource efficiency.
User Feedback and Iterative Improvement:
Continuously gather user feedback to refine the AI’s capabilities. User insights are invaluable for identifying practical areas of improvement. Establishing a feedback loop where user suggestions are systematically analyzed can lead to iterative enhancements that align with actual user needs and expectations.
Enhanced Security and Privacy Measures:
As AI models handle sensitive data, ensure that security and privacy measures are continuously updated. Conduct regular audits and adopt advanced encryption and anonymization techniques to protect user information. Staying compliant with data protection regulations like GDPR is imperative to avoid potential legal issues.
By following these recommendations, the AI’s performance and reliability can be incrementally improved, ensuring it remains a valuable asset capable of adapting to evolving demands and technological landscapes.
Now it's your turn. Tell what AI you want to build.
AI Agent
Structured Output
Classification model
Marketing Engine