← Work

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.

Live demo /Python /FastAPI /Postgres /pgvector /RAG /LLM evals /2026

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

  1. 01 →

    Parsing

    PDF → 589 articles with their structure, footnotes split off, numbering validated

  2. 02 →

    Retrieval

    Article-aware chunks, bge-m3 vectors in pgvector, six articles handed to the model

  3. 03 →

    Answer

    Gemini answers in claims, each with an article and a verbatim quote

  4. 04 →

    Verification

    The quote must be in the cited article, or the claim is dropped

  5. 05 →

    Refusal

    No verified claim left: Fasl refuses and says why

  6. 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

Each answer reads as a memo: every sentence carries a source number, and the verified quotes sit highlighted in the margin.
Selecting a sentence shows its evidence: articles given to the model, the cited article’s rank, the quote found word for word.
The full article, with its place in the code, the quoted passages highlighted, the source and the version date.
A question in Arabic about maternity leave, answered and cited from Article 152.
Outside the code (the price of a passport): Fasl refuses, listing the articles it checked and the reason.
The start page: suggested questions in French and Arabic, plus one outside the code.
On a phone, the margin moves under the answer.

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.

saadel © 2026