by he-yufeng
AI agent that reads the fine print so you don't have to. Upload any contract → get red flags, unfair terms, and plain-English explanations in seconds.
# Add to your Claude Code skills
git clone https://github.com/he-yufeng/ContractGuardAI-powered contract review agent — never sign a bad contract again.
Upload any contract → get red flags, unfair terms, and plain-English explanations in seconds.
Every year, millions of people sign contracts they don't fully understand — apartment leases with hidden penalties, employment agreements with overly broad non-competes, NDAs that silently strip away your rights. Hiring a lawyer costs $300-500/hour. Most people just sign and hope for the best.
ContractGuard changes that. It's an open-source AI agent that reads every clause of your contract, flags problems in plain language, and tells you exactly what to negotiate — all in under 30 seconds.
What makes it different from ChatGPT?
contractguard scan my-lease.pdf
✔ Parsed my-lease.pdf (4,521 characters)
⬤ RED FLAGS (5 found)
==================================================
1. Non-refundable security deposit
Clause: Section 3
"The security deposit is non-refundable and shall
be retained by Landlord upon termination"
Most states require deposits to be refundable.
This clause is likely illegal in California.
Suggestion: Remove "non-refundable" language.
2. Unlimited landlord access without notice
Clause: Section 5
"Landlord shall have the right to enter the Property
at any time, with or without notice"
California law requires 24-hour written notice.
Suggestion: Add "with 24 hours written notice"
3. Tenant pays for structural repairs
Clause: Section 4
"Tenant is responsible for all maintenance and repairs
including plumbing, electrical systems, and structural elements"
Structural repairs are typically the landlord's responsibility.
Suggestion: Limit tenant responsibility to minor maintenance only.
4. One-sided termination clause
Clause: Section 10
"Landlord may terminate this Lease at any time with
thirty (30) days' written notice for any reason"
Tenant has no equivalent right. This creates an imbalance.
Suggestion: Add mutual termination rights or require cause.
5. Tenant pays landlord's attorney fees regardless of outcome
Clause: Section 12
"Tenant shall be responsible for all attorney's fees
incurred by Landlord, regardless of the outcome"
One-sided fee-shifting discourages tenants from asserting rights.
Suggestion: Change to mutual fee-shifting (loser pays).
⚠ WARNINGS (3 found)
==================================================
1. 90-day notice period for non-renewal
Clause: Section 1
Suggestion: Negotiate down to 30-60 days.
2. 15% rent increase cap on renewal
Clause: Section 2
Suggestion: Negotiate a lower cap or tie to CPI.
3. No subletting without landlord consent (may withhold for any reason)
Clause: Section 9
Suggestion: Add "consent shall not be unreasonably withheld."
✔ PROTECTIONS (2 found)
==================================================
✔ Written notice required for termination (Section 1)
✔ Lease modification requires written agreement from both parties (Section 13)
❓ MISSING PROTECTIONS (4)
✗ No habitability guarantee
✗ No grace period for lease violations before termination
✗ No limit on late fees
✗ No provision for return of security deposit after move-out
FAIRNESS SCORE: D (28/100)
5 red flags 3 warnings 2 protections 4 missing
pip install contractguard
ContractGuard works with any OpenAI-compatible API. Pick one:
Option A: OpenRouter (recommended) — access to Claude, GPT-4, DeepSeek, Gemini, and 100+ models through a single API key:
export OPENROUTER_API_KEY=sk-or-...
Option B: OpenAI directly:
export OPENAI_API_KEY=sk-...
export OPENAI_BASE_URL=https://api.openai.com/v1
Option C: Local models via Ollama — your contract data never leaves your machine:
export OPENAI_BASE_URL=http://localhost:11434/v1
export OPENAI_API_KEY=ollama
contractguard scan my-contract.pdf
That's it. Three steps, under 60 seconds.
# Basic scan — PDF, DOCX, or TXT
contractguard scan lease.pdf
contractguard scan employment-agreement.docx
contractguard scan nda.txt
# Choose a specific model
contractguard scan contract.pdf --model openai/gpt-4o
contractguard scan contract.pdf --model anthropic/claude-sonnet-4
contractguard scan contract.pdf --model google/gemini-2.5-pro
contractguard scan contract.pdf --model llama3.1 # local via Ollama
# Export the report as a markdown file
contractguard scan contract.pdf --output report.md
# Get structured JSON output (for integrations or scripting)
contractguard scan contract.pdf --json
# Pass API key directly (instead of env variable)
contractguard scan contract.pdf --api-key sk-or-...
Use ContractGuard as a library in your own applications:
from contractguard.analyzer import analyze_contract
from contractguard.parser import extract_text
# Step 1: Extract text from any supported document
text = extract_text("my-lease.pdf")
# Step 2: Run the AI analysis
result = analyze_contract(text)
# Step 3: Use the structured results
print(f"Contract Type: {result.contract_type.value}")
print(f"Fairness Score: {result.fairness_grade} ({result.fairness_score}/100)")
print(f"Parties: {', '.join(result.parties)}")
print(f"\n{len(result.red_flags)} Red Flags:")
for flag in result.red_flags:
print(f" - {flag.title} (Clause: {flag.clause})")
print(f" Issue: {flag.explanation}")
print(f" Fix: {flag.suggestion}")
print(f"\n{len(result.warnings)} Warnings:")
for warning in result.warnings:
print(f" - {warning.title}: {warning.explanation}")
print(f"\n{len(result.good_clauses)} Protections:")
for protection in result.good_clauses:
print(f" + {protection.title}: {protection.explanation}")
print(f"\n{len(result.missing_protections)} Missing Protections:")
for missing in result.missing_protections:
print(f" ? {missing}")
# Export to markdown
from contractguard.report import generate_markdown_report
md = generate_markdown_report(result)
with open("report.md", "w") as f:
f.write(md)
When using --json, ContractGuard outputs a structured JSON object you can pipe to other tools:
{
"contract_type": "lease",
"summary": "A 12-month residential lease with several one-sided clauses...",
"parties": ["Apex Property Management LLC", "Tenant"],
"key_terms": ["Duration: 12 months", "Rent: $3,200/month", "Deposit: $6,400"],
"red_flags": [
{
"title": "Non-refundable security deposit",
"severity": "red",
"clause": "Section 3",
"quote": "The security deposit is non-refundable...",
"explanation": "Most states require deposits to be refundable...",
"suggestion": "Remove non-refundable language."
}
],
"warnings": [...],
"good_clauses": [...],
"missing_protections": [...],
"fairness_score": 28,
"fairness_grade": "D"
}
| Format | Extension | Notes |
|--------|-----------|-------|
| PDF | .pdf | Text-based PDFs. Scanned/image-based PDFs require OCR (coming soon). |
| Word | .docx | Microsoft Word documents |
| Plain Text | .txt | Plain text files |
| Markdown | .md | Markdown files |
| Rich Text | .rtf | Rich Text Format files |
ContractGuard automatically detects the contract type and tailors its analysis accordingly. Each type has specific red flags and industry-standard protections it checks for:
| Contract Type | What ContractGuard Checks | |---|---| | Residential Leases | Rent increases, deposit refundability, maintenance obligations, landlord access rights, early termination penalties, habitability guarantees | | NDAs / Confidentiality | Scope of "confidential information" (too broad?), duration, non-solicitation, non-compete, carve-outs for prior knowledge, return/destruction of materials | | Employment Contracts | Non-compete scope & duration, IP assignment (does employer own your side projects?), termination notice period, severance, at-will vs. for-cause, benefits | | Freelance / Contractor | Payment terms & schedule, kill fees, IP ownership, indemnification, scope creep protections, late payment penalties | | SaaS Terms of Service | Data ownership & portability, auto-renewal & cancellation, SLA guarantees, limitation of liability, unilateral modification rights | | Loan Agreements | Interest rate (fixed vs. variable), prepayment penalties, default triggers, personal guarantee scope, collateral requirements | | Purchase Agreements | Warranty terms, return/refund policy, liability limits, dispute resolution (arbitration vs. court), force majeure |
pdfplumber to handle complex layouts. For DOCX, uses python-docx to read all paragraphNo comments yet. Be the first to share your thoughts!