Case study · Contralyse
Nine agents, one contract, plain language
contralyse.ma analyzes, drafts and revises contracts under Moroccan law. Upload a contract and nine AI agents review it clause by clause, then deliver a report a non-lawyer can read and an improved draft.
- Role
- Full-Stack AI Engineer
- Company
- Juridata, Tangier
- Year
- 2026
- Status
- Live, in production

Results
- 9
- Analysis agents, each with a strict JSON schema
- Hybrid
- Legal search, filtered to the laws in force at signing
- 379
- Back-end tests, run in CI before every deploy
01
The problem
Reviewing a contract well takes legal knowledge most signers do not have, and a lawyer’s time that is hard to justify for every agreement.
One prompt to a general chatbot is not a review either: it does not check Moroccan law step by step, it mixes every issue into one answer and it rarely says why something matters. Contralyse needed a review that is thorough, structured and readable without legal training.
02
Nine agents, one job each
Instead of one prompt that tries to do everything, the contract goes through nine narrow agents. Each step unlocks only when the one before it is done.
- 01
Structure. Reads how the contract is organized, keeping its text in the original language.
- 02
Compliance. Checks it against Moroccan law, using laws and Court of Cassation rulings retrieved for this contract. Starts on its own.
- 03
Ambiguity. Flags clauses that can be read more than one way, and how a court would likely read them.
- 04
Consistency. Looks for provisions that contradict each other.
- 05
Risk score. Turns the findings into a risk score, and stops the analysis on a fatal validity defect such as a missing essential term.
- 06
Risk balance. Shows how the risks are split between the parties.
- 07
Strategy. Suggests how to strengthen the position of the party the user selects.
- 08
Rewrite. Rewrites the contract with the fixes applied.
- 09
Report. Writes an executive report.
03
Engineering the agents
Custom orchestration, no agent framework: every model call goes through one function with a strict contract.
- Each agent’s output is a Pydantic model turned into a strict JSON schema; answers are validated, and cut-off answers are rejected.
- Three Claude tiers (Opus, Sonnet, Haiku) through LiteLLM; each step picks the tier and temperature it needs.
- Risk scores are computed in code, with fixed weights for compliance, contradictions, case law and ambiguity; the model only makes the go/no-go call.
- Contract text is treated as untrusted input: it is wrapped in delimiters and stripped of look-alike tags, to resist prompt injection hidden in uploaded documents.
- Long analyses return at once and report progress; contract creation streams its steps live (SSE).
- A failed step keeps an error log and can be retried by the user after a short cooldown.
04
Grounded in Moroccan law
The compliance agent does not answer from memory: it searches the law first.
- The model writes short Arabic keyword queries; each one runs in parallel against Juridata’s legal search over Moroccan laws and Court of Cassation rulings.
- That search combines meaning-based and keyword (BM25) results in one ranking.
- Only laws in force on the contract’s signing date are kept.
- Hits under a confidence threshold are dropped; exact citations and laws still in force come first.
- Failed searches are retried, and the step fails cleanly when more than half of them fail.
05
Around the pipeline
Contralyse is a full product, not a demo.
- Upload a PDF, a Word or text file, or photos: everything becomes one PDF that the model reads directly.
- PDF reports, Word and PDF export of the rewritten contract, and audio summaries.
- Contract creation, revision (amendments, addenda) and translation.
- Electronic signature with DamanSign, credit-based billing with a ledger and refunds, payments with Payzone.
- Arabic, French, English and Spanish.
- A connector (MCP) so Claude and ChatGPT users can call Contralyse.
06
What I did
I wrote most of the agent pipeline and most of the React front end.
- 01
The analysis agents: prompts, schemas, scoring and orchestration
- 02
The shared LLM layer, including the move from Gemini to Claude tiers
- 03
The legal-search client and the compliance agent’s retrieval step
- 04
The React screens for analysis, contract creation and the editor
07
Stack
- React
- TypeScript
- FastAPI
- Claude (Opus, Sonnet, Haiku)
- LiteLLM
- Pydantic
- RAG
- MariaDB
- DamanSign
- Payzone
- Docker
Have a similar problem, or a role where this fits?