30 Sakr Qurish St, Sheraton, Cairo, Egypt

Dare to Create

Hossam X Studios — #1 Best Creative Digital Agency Since 2021. We take care of your IT — web, mobile, software, marketing and design — so you can focus on your business.

Home / Projects / XS Lawyer / Case Study 02

Every section, explained.

5 working sections inside LLM — Domain-Trained Legal AI — each one a screen we designed, built and tested in the live system.

01 / 05 Egyptian Legal Corpus
Section 01

Egyptian Legal Corpus

A curated and cleaned knowledge base spanning the Egyptian Constitution, Civil Code, Commercial Law, Criminal Law, Family / Personal Status Law and Labor Law — each source indexed by article, paragraph and amendment date so the model can cite back to a specific statutory anchor.

  • Constitution, Civil, Commercial, Criminal, Family, Labor
  • Indexed by article + paragraph + amendment date
  • Bilingual EN / AR source pairs where available
  • Versioned corpus with audit trail per source
02 / 05 Citation Enforcement Pipeline
Section 02

Citation Enforcement Pipeline

The hallucination-cut layer. Every model answer is post-processed against the corpus: if the citation can't be matched to an article in the knowledge base, the answer is downgraded to "uncited reasoning" and flagged in the UI — so a user can always tell what's grounded and what isn't.

  • Post-generation citation match against the corpus
  • Uncited answers downgraded and flagged in the UI
  • Citation schema baked into the response format
  • Prompt-eval suite over ~200 real legal questions
03 / 05 Document Analysis — Contracts & PDFs
Section 03

Document Analysis — Contracts & PDFs

Users drop a contract PDF into the chat and the system extracts clauses, flags risk language (auto-renewal, exclusive jurisdiction, unilateral amendments), and explains them in plain Arabic or English — with quota metering tied to each plan's file allowance.

  • PDF parsing + clause extraction
  • Risk-language flagging (renewal, jurisdiction, etc.)
  • Plain-language explanations in EN or AR
  • Per-plan file quota enforced at upload
04 / 05 Multilingual EN / AR Chat
Section 04

Multilingual EN / AR Chat

The conversational surface — streaming responses, mid-thread language switching (a user can ask in Arabic and request the answer in English on the same turn), and a citation panel that renders the cited articles inline next to each answer.

  • Streaming responses with token-level rendering
  • Mid-thread EN ↔ AR language switching
  • Inline citation panel beside every answer
  • Conversation history persists per subscription
05 / 05 Credit-Based Usage Metering
Section 05

Credit-Based Usage Metering

Every chat message decrements a credit and every file upload counts against the file quota — metered at the chat layer, enforced against the Features (entitlements) module in the admin, and surfaced live on the conversation header so the user always knows where they stand.

  • Per-message credit decrement at the chat layer
  • Per-upload file quota enforced against Features module
  • Live credit + file counters pinned to the header
  • Soft-block + upgrade CTA when a quota runs out

Need a llm — domain-trained legal ai like this?

If your product is a model wrapped in a Notion doc, that's exactly the gap we close — billing, admin, multilingual, security, and all. Let's talk.