Ai summarization clause extraction

From CraftOS-dev/craftbot-agent-bundles · View interactive version

Ai summarization clause extraction is an AI agent skill from the GitHub repository CraftOS-dev/craftbot-agent-bundles. Summarize long contracts (MSA, customer T&C, 100+ page agreements) and extract named clauses (parties, term, fees, indemnity, IP, LoL, governing law, termination) using long-context LLMs (Claude Sonnet 4.5+, Gemini 2.0 Pro), CLM AI (Evisort, LinkSquares, Ironclad AI, Lexion AI), or local NER + few-s

How to use this skill

Skill file

AI summarization + clause extraction — Claude / Gemini long-context + CLM AI

This skill ships the "what's in this contract" pipeline. For 1-100 docs: long-context LLM via filesystem. For 1K+ docs: CLM-native AI (Evisort, LinkSquares).

When to use

User says:

Companion skills:

Setup

# Claude API (long-context summarization)
pip install anthropic
# Required env: ANTHROPIC_API_KEY

# Gemini (alt long-context)
pip install google-generativeai
# Required env: GOOGLE_API_KEY

# Local NER + classification (for SLA + private deploys)
pip install spacy transformers
python -m spacy download en_core_web_lg

# CLM AI (Evisort / LinkSquares / Ironclad AI)
# Use clm-ironclad-contractworks-integration skill

# Helpers
pip install python-docx pypdf PyPDF2 tiktoken

Common recipes

Recipe 1: Pick the engine

| Engine | Best for | Cost | Notes |

|---|---|---|---|

| Claude Sonnet 4.5+ | Single-doc deep summary | API ($/M tokens) | 1M-token context |

| Claude Opus | Very high accuracy on complex contracts | Higher API | Slowest, most expensive |

| Gemini 2.0 Pro | Free-tier alt | Free / API | 1M-token context |

| GPT-4 / 5 | OpenAI-resident | API | 128K-200K context |

| Evisort AI | Bulk semantic search across repo | Per-seat license | Best-in-class clause AI |

| LinkSquares AI | Post-exec analytics + extraction | License | Clause library + dashboards |

| Ironclad AI Assist | Pre-exec workflow | License | Negotiation assistance |

| Local NER (spaCy + few-shot LLM) | Private / air-gapped | Compute | Latency low; accuracy medium |

Default for single contracts: Claude long-context. For 1K+ docs: pair with CLM AI. For air-gapped: local NER + small LLM.

Recipe 2: Standard clause taxonomy

STANDARD_CLAUSES = [
    "parties",                # who is contracting
    "effective_date",
    "term_length",
    "auto_renewal",
    "termination_for_cause",
    "termination_for_convenience",
    "payment_terms",
    "fees_structure",          # flat / per-unit / hybrid
    "late_payment",
    "limitation_of_liability",
    "indemnity",
    "warranties",
    "ip_assignment",
    "ip_license_grant",
    "confidentiality",
    "data_processing",
    "data_security",
    "governing_law",
    "venue_forum",
    "dispute_resolution",      # arbitration / litigation
    "force_majeure",
    "assignment",
    "amendment",
    "notices",
    "severability",
    "entire_agreement",
    "counterparts",
    "service_levels",
    "non_compete",
    "non_solicit"
]

Recipe 3: Claude — summarize a contract

import anthropic
from pypdf import PdfReader

def read_pdf(path):
    return "\n".join(p.extract_text() for p in PdfReader(path).pages)

text = read_pdf("acme-msa.pdf")
client = anthropic.Anthropic()
resp = client.messages.create(
    model="claude-sonnet-4-7",
    max_tokens=4000,
    system="You are a senior commercial contracts lawyer. Output factual, citation-anchored summaries; refuse to draft legal advice; flag ambiguity.",
    messages=[{"role":"user","content": f"""Summarize this MSA. For each section below, give 1-3 bullet findings + the section number cited from the doc:

Parties, Effective date, Term + renewal, Fees, Payment terms,
Limitation of Liability, Indemnity, IP assignment, Warranties,
Confidentiality, Data processing, Governing law, Venue, Termination, SLA.

Then list 5 unusual or risky terms with a one-line risk rating (low/medium/high).

Contract:
{text}"""}]
)
print(resp.content[0].text)

Hand off binding interpretation to legal-counsel.

Recipe 4: Claude — structured JSON extraction

resp = client.messages.create(
    model="claude-sonnet-4-7",
    max_tokens=4000,
    system="Extract contract clauses. Return strict JSON only.",
    messages=[{"role":"user","content": f"""Extract the following clauses from the contract below. Return JSON:
{{
  "parties": [{{"name":"","role":""}}],
  "effective_date": "ISO",
  "term_months": 0,
  "auto_renewal": {{"present": false, "notice_days":0}},
  "limitation_of_liability": {{"cap_type":"","cap_value":"","exclusions":[]}},
  "indemnity": {{"customer_indemnifies": false, "vendor_indemnifies": false, "covered_claims":[]}},
  "governing_law": {{"state":"","country":""}},
  "venue": "",
  "termination_for_convenience": {{"present": false, "notice_days":0}},
  "raw_text_refs": {{ "section_name":"section_n.n" }}
}}

Use null where uncertain; do not invent.

Contract:
{text}"""}]
)
import json
clauses = json.loads(resp.content[0].text)

Recipe 5: Compare two contracts (rev vs prior)

prior_text = read_pdf("acme-msa-v1.pdf")
new_text = read_pdf("acme-msa-v2.pdf")
resp = client.messages.create(
    model="claude-sonnet-4-7",
    max_tokens=4000,
    system="You are reviewing contract changes between versions. Be precise about what changed.",
    messages=[{"role":"user","content": f"""Compare versions of this MSA. For each of the standard clauses (parties, term, LoL, indemnity, ...), state whether it changed and quote the before/after key lines.

V1:
{prior_text}

V2:
{new_text}"""}]
)

Recipe 6: Bulk summarize 100+ contracts (corpus)

import pathlib, json
from concurrent.futures import ThreadPoolExecutor

results = []
def process_one(path):
    text = read_pdf(path)
    # Recipe 4 for structured JSON
    return {"path": str(path), "clauses": extract_clauses(text)}

with ThreadPoolExecutor(max_workers=4) as ex:
    for r in ex.map(process_one, pathlib.Path("contracts/").glob("*.pdf")):
        results.append(r)

# Persist
with open("clauses.jsonl","w") as f:
    for r in results:
        f.write(json.dumps(r) + "\n")

Pricing/rate-limit aware: parallelism 4-8 for Claude API.

Recipe 7: Evisort — semantic clause search

curl -X POST https://api.evisort.com/v1/search \
  -H "Authorization: Bearer $EVISORT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "query": "limitation of liability cap less than 12 months fees",
    "agreement_types": ["MSA","SaaS"]
  }'

Returns ranked list of contracts + clause snippets matching natural query.

Recipe 8: LinkSquares — pull all clauses for a contract

curl https://api.linksquares.com/v1/contracts/$ID/clauses \
  -H "Authorization: Bearer $LINKSQUARES_API_KEY"

Returns extracted clauses + confidence scores for ~30 standard categories.

Recipe 9: Hybrid — local NER pre-pass + LLM verification

import spacy
nlp = spacy.load("en_core_web_lg")
doc_text = read_pdf("acme-msa.pdf")
doc = nlp(doc_text)
# Pull obvious entities (parties, dates, money)
candidates = {
    "parties":   [e.text for e in doc.ents if e.label_ == "ORG"],
    "dates":     [e.text for e in doc.ents if e.label_ == "DATE"],
    "money":     [e.text for e in doc.ents if e.label_ == "MONEY"]
}
# Then LLM verifies + categorizes
verified = llm_verify(candidates, doc_text)

Cheaper at scale because the LLM only sees flagged spans.

Recipe 10: Chunking for >1M-token contracts (rare)

# Most contracts fit; treaties/master agreements might not
import tiktoken
enc = tiktoken.encoding_for_model("gpt-4o")
tokens = enc.encode(text)
CHUNK = 200_000
chunks = [enc.decode(tokens[i:i+CHUNK]) for i in range(0, len(tokens), CHUNK)]
# Summarize each chunk, then meta-summarize
chunk_summaries = [summarize(c) for c in chunks]
final = summarize("\n".join(chunk_summaries))

Recipe 11: Citation-anchored output (page + section)

# Provide page+section context in prompt
resp = client.messages.create(
    model="claude-sonnet-4-7",
    max_tokens=4000,
    messages=[{"role":"user","content": f"""For each finding, cite the section number (e.g., "§4.2") and page (if visible).

{text_with_page_markers}"""}]
)

Pre-process the PDF to inject [Page 12] markers between page contents.

Recipe 12: Risk-tier grading

RISK_TIERS = {
    "low": "Standard market terms",
    "medium": "Acceptable with negotiation",
    "high": "Material business risk; require legal review"
}
resp = client.messages.create(
    model="claude-sonnet-4-7",
    max_tokens=2000,
    system="Rate each clause: low / medium / high risk relative to typical SaaS T&C 2026 market. Cite reasoning.",
    messages=[{"role":"user","content": f"...{text}"}]
)

Always hand off high-risk findings to legal-counsel.

Recipe 13: Term-sheet style summary output

# Contract Summary — Acme MSA

**Parties:** Widget Co (Vendor) ↔ Acme Corp (Customer)
**Effective:** 2026-07-01    **Term:** 36 months    **Auto-renew:** Yes, 60-day notice
**Fees:** $240K/yr fixed; annual escalator 3%
**LoL Cap:** 12 months fees paid    **Mutual cap:** No (vendor only)
**Indemnity:** Vendor IP infringement; Customer breach of confidentiality
**Governing law:** Delaware    **Venue:** Delaware Court of Chancery
**SLA:** 99.9% uptime    **Service credits:** Cap 10% monthly fees
**Notable / risk:**
- §8.3 — uncapped liability for breach of confidentiality (HIGH)
- §11 — exclusive forum (MEDIUM — usability)
- §12 — IP indemnity excludes open-source claims (LOW)

Examples

Example 1: One-contract due-diligence summary

Goal: Acquirer needs MSA summary for diligence.

Steps:

  1. Recipe 3 — Claude summary.
  2. Recipe 4 — structured JSON for cap-table-style row.
  3. Recipe 12 — risk tier.
  4. Recipe 13 — term-sheet style markdown for partners.

Result: Standard-format diligence row per contract.

Example 2: Quarterly clause audit across 200 contracts

Goal: Find weak indemnity caps; renegotiate top 10.

Steps:

  1. Recipe 6 — bulk extract via Claude.
  2. Filter rows where limitation_of_liability.cap_value < 6 months fees.
  3. Rank by deal value.
  4. Hand off top 10 to legal-counsel for redline strategy.

Result: Risk-prioritized renegotiation list.

Example 3: Enterprise — Evisort + LinkSquares hybrid

Goal: 5K-contract repo; need natural-language search.

Steps:

  1. Recipe 7 — Evisort for "find all contracts with weak indemnity."
  2. Recipe 8 — pull clauses for the top 50 results.
  3. Recipe 5 — diff vs the org's template to spot deviations.

Result: AI-assisted contract intelligence with auditable extraction.

Edge cases / gotchas

Sources

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.