👉 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 with vision-language models (VLMs) to extract key clauses and terms from contracts entirely on local hardware. Feed it any legal agreement, whether plain text, PDF, DOCX, or a scanned contract image, 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
TextExtractionwith VLMs to extract structured data from legal documents and scanned contract images. - Define extraction schemas with
TextExtractionElementfor contract-specific fields. - Extract both factual data (dates, amounts) and interpretive analysis (risk flags, clause summaries).
- Process text content with
SetContent(string)or load documents and images withAttachment.
Why a Local Contract Analyzer with LM-Kit.NET?
- Scanned contract support: VLMs process photographed or scanned contracts directly, no separate OCR step required.
- 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, even from scanned documents.
- Procurement Departments: extract and compare terms across vendor agreements, including photographed contracts.
- 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.
- Scanned documents: process photographed or scanned contracts directly with vision-language models.
- 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 vision-language models optimized for document understanding.
- 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, .png, .jpg).
- View the extracted key terms with color-coded output.
- View the full JSON output for integration.
- Type
- Loops until you type
q.
Key Features
- Vision-Language Models: Process scanned contracts, photographs, and standard text formats using VLMs.
- 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, scanned image) │
└───────────────────┬─────────────────────────────┘
│
▼
┌──────────────────────────────────────────────────┐
│ Vision-Language Model (VLM) │
└───────────────────┬──────────────────────────────┘
│
▼
┌──────────────────────────────────────────────────┐
│ 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.5:9b");
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
};
// Text content
textExtraction.SetContent(contractText);
// Or scanned contract image / PDF
textExtraction.SetContent(new Attachment("contract_scan.png"));
var result = textExtraction.Parse();
Console.WriteLine(result.Json);
⚙️ Getting Started
Prerequisites
- .NET 8.0 or later
- Sufficient VRAM for the selected model (2.5-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 vision-language 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 (text, PDF, DOCX, or scanned image). - View the extracted key terms and JSON output.
- Type
qto exit.
🔧 Troubleshooting
Incomplete clause extraction
- Try a larger model (12B+) 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.
Scanned contract issues
- Ensure the image is clear and well-lit for best VLM results.
- Higher resolution images produce better extraction accuracy.
- Try a larger VLM if extraction from images is incomplete.
🚀 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 VLMs.
- Database integration: pipe JSON output into a contract lifecycle management (CLM) system.
- Batch processing: scan a folder of contract images and extract terms from each.
📚 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.