Beyond LLMs: How I Used AWS Cedar & Strands SDK to Eliminate Predatory Indian Contracts
A Deep-Dive into Building DeFang (Bharat Edition) for the First Commit | Bharat Builds Tour Hackathon
1. The Ground Reality: Why Indian Contracts Are Broken
If you have ever rented an apartment in Indiranagar, Bengaluru, or signed an offer letter at a high-growth Indian tech startup, you have felt the invisible dread of signing an agreement you barely understand.
- The Rental Trap: Landlords demand extortionate 10-month deposits (often ₹3,50,000+ in cash) and enforce non-negotiable "1-month painting deductions" upon exit, even though Section 15 of the Model Tenancy Act 2021 explicitly protects tenants against normal wear and tear.
- The Tech Fresher Bond: Fresh engineering graduates are coerced into signing void 24-month post-exit non-compete covenants and arbitrary liquidated damages of ₹2,50,000 under the guise of "training expenses," directly violating Section 27 of the Indian Contract Act 1872.
- The Freelance Asymmetry: Gig developers face predatory 4% daily late penalties (>1,400% APR) and 90-day vs. 0-day termination asymmetries.
Hiring an advocate to review a 12-page contract costs between ₹5,000 and ₹15,000—completely out of reach for a student or migrant worker.
2. Why Generic LLMs Fail in Legal Safety
When hackathon developers tackle this problem, the knee-jerk reaction is simple: "Send the PDF to an LLM with a prompt like: 'Are there any bad clauses?'"
This is dangerous.
LLMs are probabilistic token predictors. In legal domains, they:
- Hallucinate Statutory Citations: They invent sections of the Indian Penal Code or Contract Act that don't exist.
- Give Inconsistent Verdicts: The same contract evaluated twice can yield conflicting advice.
- Cannot Be Mathematically Audited: You cannot present a probabilistic LLM token log as a verifiable legal certification.
We realized early on: We didn't need a bigger language model; we needed a formal, deterministic policy engine.
That is where AWS Cedar entered our architecture.
3. The Dual-Engine Architecture: AI Extraction Meets AWS Cedar Verification
I architected DeFang around a clean, decoupled Dual-Engine design:
┌────────────────────────────────────────────────────────────────────────────────────────┐│ DEFANG DUAL-ENGINE FLOW │├──────────────────────────┬─────────────────────────────────┬───────────────────────────┤│ 1. INGESTION & OCR │ 2. STRANDS AGENT SDK │ 3. FORMAL AWS CEDAR ││ │ │ ││ Raw Contract (PDF/Text) │ Extracts structured parameters │ Deterministic Evaluation ││ - Tenancy agreements │ - amount_inr: 350000 │ - Evaluates 8 .cedar ││ - Employment bonds │ - monthly_rent_inr: 35000 │ statutory policy files ││ - Freelance MSAs │ - painting_mandatory: true │ - Verdict: ALLOW / DENY ││ │ - non_compete_months: 24 │ - Zero Hallucinations │└──────────────────────────┴─────────────────────────────────┴───────────────────────────┘- Step 1 (Ingestion): Handles digital PDFs, raw contract text, and mobile camera snapshots of physical ₹100 e-stamp papers at the broker's desk.
- Step 2 (Strands Agents SDK): Operates strictly as a structured parameter extractor. It extracts entity covenants into machine-readable JSON entities (e.g.,
amount_inr,monthly_rent_inr,painting_deduction_mandatory,notice_period_days). It does not make the legal judgment.
- Step 3 (AWS Cedar Policy Engine via
cedarpy): The structured entities are passed to AWS Cedar, executing in native Rust, which deterministically evaluates them against real Indian statutory policies.
4. Encoding Real Indian Jurisprudence into AWS Cedar
AWS Cedar’s expressive, declarative syntax allowed us to translate complex Indian statutes into mathematical policies. We authored 8 formal
.cedar policy definitions.Example 1: Section 9 of the Model Tenancy Act 2021 (Deposit Cap)
The statute mandates that residential security deposits must not exceed 2 to 3 months of agreed rent. Here is our formal Cedar policy (
deposit_cap.cedar ):cedar// cite: Model Tenancy Act 2021, Sec 9// Forbid security deposits exceeding 3 months of agreed monthly rent@id("deposit_cap")@cite("Model Tenancy Act 2021, Sec 9")@title("Excessive Security Deposit Cap Violation")forbid ( principal, action == Action::"enforce_clause", resource)when { resource.category == "deposit" && resource.monthly_rent_inr > 0 && resource.amount_inr > (resource.monthly_rent_inr * 3)};When an Indiranagar agreement specifies ₹3,50,000 deposit on a ₹35,000 monthly rent:
-
amount_inr (350000) > monthly_rent_inr * 3 (105000)evaluates to TRUE.
- Cedar triggers an immediate, mathematically guaranteed
DENYin 3.8 milliseconds.
Example 2: Section 27 of the Indian Contract Act 1872 (Non-Competes)
Under Indian law, all post-termination non-compete agreements are void ab initio (Niranjan Shankar Golikari v. Century Spg & Mfg Co.):
cedar// cite: Indian Contract Act 1872, Sec 27// Restraint of trade is void ab initio under Indian law@id("non_compete")@cite("Indian Contract Act 1872, Sec 27")@title("Unlawful Restraint of Trade")forbid ( principal, action == Action::"enforce_clause", resource)when { resource.category == "employment" && resource.non_compete_months > 0};
5. Engineering for Real-World Bharat: 4 Localized Innovations
Technology fails in India if it only works in English on a MacBook in Indiranagar. We built DeFang for the ground reality:
- Hidden Rupee Trap (₹) Simulator: Abstract legal scores mean nothing to an ordinary tenant. We calculate the exact rupee liability:
₹3,50,000 (excess deposit) + ₹35,000 (painting deduction) + ₹3,51,050 (penal interest) = ₹7,36,050 Total Trapped Liability.
- Power Imbalance Meter: Measures contract hypocrisy (e.g., Tenant: 90 days notice or forfeit deposit; Landlord: 15 days notice with 0 penalty) and flags a 95% Landlord Bias.
- Multilingual Vernacular Voice Readout: Integrated the native Web Speech API with regional accents in Kannada (
kn-IN), Telugu (te-IN), Hindi (hi-IN), and English (en-IN), allowing illiterate and semi-literate migrant workers to hear their risks read aloud.
- 1-Click WhatsApp Negotiation Diplomat: Ordinary citizens cannot write legal letters. We generate calibrated counter-proposals (Polite, Firm, Statutory) with direct 1-click dispatch into WhatsApp Web and Mobile.
6. Key Takeaways for AWS Builders
Building DeFang taught us three fundamental lessons:
- Decouple Reasoning from Enforcement: Use AI models for what they do best (parsing fuzzy, messy human language) and use formal policy engines like AWS Cedar for what they do best (uncompromising, deterministic rules).
- Offline-First Resilience: By packaging Cedar policies with
cedarpy, the entire evaluation runs locally on-device. Zero network requests, zero cloud API bills, and sub-5ms latency.
- Build for Bharat: Adding vernacular speech, camera capture for physical e-stamps, and WhatsApp integration transforms a developer prototype into a lifesaver for 1.4 billion citizens.
Built with ❤️ for the First Commit | Bharat Builds Tour Hackathon.
Repository: github.com/Pranay207/DeFang
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article