Fasl | فصل
Question answering over the Moroccan labour code, in French and Arabic. Every sentence of an answer cites the article it comes from, and the quote is checked against the article text.
The Challenge
A legal answer from a language model is only as good as its sources, and a model will happily invent an article number or a quote. For a lawyer or an HR team, a fluent answer with a fake citation is worse than no answer at all. The goal: every claim traceable to the exact words of the law, an honest refusal when the text doesn’t cover the question, and numbers to prove both.
The pipeline
01 →
Parsing
PDF → 589 articles with their structure, footnotes split off, numbering validated
02 →
Retrieval
Article-aware chunks, bge-m3 vectors in pgvector, six articles handed to the model
03 →
Answer
Gemini answers in claims, each with an article and a verbatim quote
04 →
Verification
The quote must be in the cited article, or the claim is dropped
05 →
Refusal
No verified claim left: Fasl refuses and says why
06
Evaluation
Separate dev and test splits, ablations, decision log
The Approach
The Code du travail (589 articles) is parsed from the Ministry of Justice PDF into articles that keep their book, title and chapter, then embedded with bge-m3 in Postgres + pgvector. For each question the six closest articles go to the model, which must answer in structured output: claims, each with an article id and a verbatim quote. Code then checks every quote against the stored article text. A claim whose quote isn’t found is dropped before display, and an answer with no verified claim becomes a refusal. Everything is measured on a synthetic question set split into dev and test: choices are tuned on dev only, the test split is frozen and run once, and every eval-driven change goes into a decision log.
The Result
Frozen test split, run once
26/30
answerable questions answered with a verified citation to the right article
43/44
claims whose quote is in the cited article
0/15
trap questions that got an answer
0.90
retrieval recall@5 (right article in the top 5)
Evaluation uses a synthetic, corpus-derived question set; citation accuracy is verified against source text; answer correctness has not been reviewed by a legal expert. The harness supports a reviewed flag for future expert validation.
On the frozen test split (45 questions, 15 of them traps outside the code), 26 of 30 answerable questions got a verified citation to the right article, 43 of 44 claims passed the quote check (the last one was dropped), and none of the 15 traps got an answer. The ablations changed the design: hybrid search (vectors + full text) did worse than plain vector search on lay-style questions, and a similarity threshold for refusals didn’t transfer from dev to test. Both were dropped. The live demo runs for free on Render, Neon and Cloudflare Workers AI, with rate limits and a privacy notice.
Screenshots
Notes
- Backend: Python 3.12, FastAPI, SQLAlchemy, Postgres + pgvector, bge-m3, Gemini (free tier).
- Hosting: Render (API), Neon (Postgres), Cloudflare Workers AI for query vectors, checked against the local model: the same top six articles on all 82 dev questions.
- Limits: French text consolidated as of 26 October 2011; the official Arabic text, which prevails, is not ingested yet; answers have not been reviewed by a legal expert.
Informational tool, not legal advice. Answers have not been reviewed by a legal expert.