👉 Try the demo: https://github.com/LM-Kit/lm-kit-net-samples/tree/main/console_net/contract_key_terms_extractor
AI Contract Key Terms Extractor for C# .NET Applications
🎯 Purpose of the Demo
AI Contract Key Terms Extractor demonstrates how to use LM-Kit.NET to extract key clauses and terms from contracts entirely on local hardware. Feed it any legal agreement and get back structured JSON with parties, dates, financials, termination conditions, IP rights, confidentiality obligations, liability caps, and risk flags.
The sample shows how to:
- Use
TextExtractionto extract structured data from legal documents. - Define extraction schemas with
TextExtractionElementfor contract-specific fields. - Extract both factual data (dates, amounts) and interpretive analysis (risk flags, clause summaries).
- Parse text content with
SetContent(string)or load documents withAttachment.
Why a Local Contract Analyzer with LM-Kit.NET?
- Confidential contracts stay private: analyze sensitive legal documents without cloud exposure.
- One API call: a single
Parse()call extracts all key terms. No agents, no chaining. - Risk detection: AI automatically flags unusual or potentially risky clauses.
- Works offline: no API keys, no internet connection required.
👥 Who Should Use This Demo
- Legal Teams: quickly review contracts and identify key terms without manual reading.
- Procurement Departments: extract and compare terms across vendor agreements.
- Startup Founders: understand key clauses before signing partnerships or vendor contracts.
- Contract Management Developers: integrate local AI-powered contract analysis into CLM systems.
- Compliance Officers: flag risky clauses and ensure policy adherence.
🚀 What Problem It Solves
- Contract review time: extract key terms in seconds instead of hours of manual reading.
- Data privacy: analyze confidential contracts without uploading to cloud AI services.
- Risk visibility: automatically surface non-compete, exclusivity, auto-renewal, and penalty clauses.
- Consistency: extract the same structured fields from every contract for easy comparison.
💻 Demo Application Overview
Console app that:
- Lets you choose from multiple models optimized for text extraction.
- Downloads models if needed, with live progress updates.
- Creates a TextExtraction instance with a contract-specific schema.
- Enters an interactive loop where you can:
- Type
sampleto analyze a built-in Master Services Agreement. - Enter a file path to analyze your own contract (.txt, .pdf, .docx).
- View the extracted key terms with color-coded output.
- View the full JSON output for integration.
- Type
- Loops until you type
q.
Key Features
- Comprehensive Extraction: Contract type, parties, dates, value, payment, termination, IP, confidentiality, liability, governing law.
- Risk Flags: AI identifies unusual or risky clauses (non-compete, exclusivity, unlimited liability, auto-renewal).
- Party Identification: Each party extracted with name, role, and address.
- Built-In Sample: Realistic Master Services Agreement for instant demo.
- JSON Output: Machine-readable structured data for contract management systems.
- Zero Configuration: No API keys, no cloud accounts, no external dependencies.
🏗️ Architecture
┌─────────────────────────────────────────────────┐
│ Contract (text, PDF, DOCX) │
└───────────────────┬─────────────────────────────┘
│
▼
┌──────────────────────────────────────────────────┐
│ TextExtraction │
│ │
│ Schema: │
│ ├── Contract Type (String) │
│ ├── Contract Title (String) │
│ ├── Parties (Array) │
│ │ └── Name, Role, Address │
│ ├── Effective Date (Date) │
│ ├── Expiration Date (Date) │
│ ├── Contract Value (String) │
│ ├── Payment Terms (String) │
│ ├── Termination Clause (String) │
│ ├── Confidentiality (String) │
│ ├── Liability Limitation (String) │
│ ├── Intellectual Property (String) │
│ ├── Governing Law (String) │
│ ├── Key Obligations (String) │
│ ├── Renewal Terms (String) │
│ └── Risk Flags (String) │
│ │
└───────────────────┬──────────────────────────────┘
│
▼
┌──────────────────────────────────────────────────┐
│ Key Contract Terms │
│ (formatted display + JSON) │
└──────────────────────────────────────────────────┘
Extraction Schema
| Field | Type | Description |
|---|---|---|
| Contract Type | String | NDA, Service Agreement, Employment, Lease, etc. |
| Contract Title | String | Official document title |
| Parties | Array | Name, role, and address of each party |
| Effective Date | Date | When the contract takes effect |
| Expiration Date | Date | End date or "Perpetual" |
| Contract Value | String | Total monetary value or fee |
| Payment Terms | String | Payment schedule and conditions |
| Termination Clause | String | Termination conditions and notice period |
| Confidentiality | String | Non-disclosure obligations summary |
| Liability Limitation | String | Liability cap or damages limitation |
| Intellectual Property | String | IP ownership and licensing provisions |
| Governing Law | String | Jurisdiction for disputes |
| Key Obligations | String | Main deliverables and obligations |
| Renewal Terms | String | Auto-renewal conditions |
| Risk Flags | String | Unusual or risky clauses identified |
Code Highlights
using LMKit.Extraction;
using LMKit.Model;
LM model = LM.LoadFromModelID("qwen3:8b");
var textExtraction = new TextExtraction(model);
textExtraction.Elements = new List<TextExtractionElement>
{
new("Contract Type", ElementType.String, "Type of contract."),
new("Parties",
new List<TextExtractionElement>
{
new("Name", ElementType.String, "Legal name of the party."),
new("Role", ElementType.String, "Role in the contract."),
new("Address", ElementType.String, "Registered address.")
},
isArray: true,
"Parties involved in the contract."
),
new("Effective Date", ElementType.Date, "When the contract becomes effective."),
new("Risk Flags", ElementType.String, "Unusual or risky clauses."),
// ... more elements
};
textExtraction.SetContent(contractText);
var result = textExtraction.Parse();
Console.WriteLine(result.Json);
⚙️ Getting Started
Prerequisites
- .NET 8.0 or later
- Sufficient VRAM for the selected model (6-18 GB depending on model choice)
Download
git clone https://github.com/LM-Kit/lm-kit-net-samples
cd lm-kit-net-samples/console_net/contract_key_terms_extractor
Run
dotnet build
dotnet run
Then:
- Select a model from the menu, or paste a custom model URI.
- Wait for the model to download (first run) and load.
- Type
sampleto try the built-in contract, or enter a file path. - View the extracted key terms and JSON output.
- Type
qto exit.
🔧 Troubleshooting
Incomplete clause extraction
- Try a larger model (14B+) for better accuracy on complex legal language.
- Ensure the full contract text is provided, not just excerpts.
Risk flags not detected
- Larger models are better at identifying subtle risk patterns.
- Check that the contract contains the relevant clauses.
PDF parsing issues
- Ensure the PDF contains selectable text (not a scanned image).
- For scanned contracts, use OCR preprocessing (see
invoice_data_extractiondemo).
🚀 Extend the Demo
- Contract comparison: extract terms from multiple contracts and generate a comparison table.
- Compliance checking: validate extracted terms against company policy rules.
- Renewal tracking: build a dashboard of upcoming contract expirations and renewals.
- Multi-language contracts: test with international agreements using multilingual models.
- Database integration: pipe JSON output into a contract lifecycle management (CLM) system.
📚 Additional Resources
- LM-Kit.NET Documentation
- TextExtraction API Reference
- TextExtractionElement API Reference
- Attachment API Reference
- LM-Kit Samples Repository
📚 Related Content
- How-To: Extract Structured Data: General guide to defining schemas and extracting structured data from text and documents.
- Glossary: Structured Data Extraction: Explains schema-driven extraction concepts used for contract analysis.
- Glossary: Extraction: Covers the broader extraction capabilities in LM-Kit.NET.
- Invoice Data Extraction Demo: Similar schema-driven extraction demo applied to invoice documents.