What it does
Risk level classification (High/Medium/Low)
Missing clause detection
Indian law compliance notes
PDF and text input support
JSON structured output
Stack
PythonAnthropic ClaudePyPDF2FastAPI
Deploy on
✓ Render✓ Railway✓ FastAPI
Full source code
Install commands are in the top comments. Copy and run.
from anthropic import Anthropic
import PyPDF2, io, json, re
from fastapi import FastAPI, UploadFile
app = FastAPI()
client = Anthropic()
PROMPT = ('Analyse this contract. Return JSON with:\n'
'- risk_summary: list of {level,issue,explanation}\n'
'- missing_protections: absent clauses\n'
'- unusual_clauses: non-standard terms\n'
'- key_numbers: {payment_terms,notice_period,liability_cap}\n'
'- india_law_notes: jurisdiction,arbitration,GST\n\nContract: {text}')
def extract_pdf(b):
return '\n'.join(p.extract_text() or '' for p in PyPDF2.PdfReader(io.BytesIO(b)).pages)
@app.post('/review')
async def review(file: UploadFile):
content = await file.read()
text = extract_pdf(content) if file.filename.endswith('.pdf') else content.decode()
resp = client.messages.create(model='claude-sonnet-4-6', max_tokens=3000,
messages=[{'role':'user','content':PROMPT.format(text=text[:15000])}])
raw = resp.content[0].text
m = re.search(r'\{.*\}', raw, re.DOTALL)
return {'analysis': json.loads(m.group()) if m else {'raw':raw}}