All B-Agent apps Home
Case study · B-Agent

B-Agent Law

An AI legal assistant for Turkish lawyers, grounded in real law.

Built it end to end: the React app, the Node.js API, the Python ingest pipeline and the Azure deployment, and runs it in production.

11Mcourt decisions searchable
48 daysmeasured publication lag
892laws refreshed article by article
51court chambers, each with its own checkpoint
The problem

Turkish lawyers spend hours finding case law and checking whether a provision is still in force. General AI chat tools invent case numbers and quote repealed articles with full confidence, which nobody can put in a petition.

The approach

Ground every answer in a corpus the app owns: court decisions, legislation and the Official Gazette, collected daily and indexed in Azure AI Search. Retrieval feeds the model, cited provisions are checked against the current law, and a citation guard removes any case number it cannot verify.

How it works

From request to answer, step by step.

  1. 01Daily collectorsCourt portals, legislation catalog, Official Gazette and regulators, one job each
  2. 02Ingest and dedupeDedupe by native id, split long texts, skip decisions already held
  3. 03Azure AI SearchAbout 11 million decisions and 46,000 legislation documents
  4. 04RetrievalRanked search over decisions, laws and the lawyer's own case files
  5. 05Current-law checkCited provisions checked against consolidated texts refreshed every day
  6. 06Model answerFast or smart tier; long drafts run as polled background jobs
  7. 07Citation guardEvery case number verified in the index, in the named chamber

What it does

  • Ask a legal question, get an answer that cites real court decisions and laws.
  • Draft 14 kinds of documents, from petitions to contracts, and export to Word, PDF or UYAP format.
  • Upload a contract and get a clause-by-clause risk map with suggested rewrites.
  • Search case law, compare two versions of a law, run legal interest calculations.
  • Keep case files, with an AI summary of every new document.

Under the hood

  • About 11 million court decisions and 46,000 legislation documents in Azure AI Search, refreshed daily.
  • Citation guard: every case number in an answer is checked against the index. Anything unverifiable is removed.
  • Each owner's content is encrypted with its own key (AES-256-GCM). One access rule for case files, no admin bypass.
  • Also ships as a Microsoft Teams app and an Outlook add-in.
Hard problems

What took real engineering.

Problem 1

Indexed is not the same as searchable

Three times, data was ingested correctly and still unreachable: search pointed at legacy indexes holding 1.45 million of 11 million documents, a scheduled workflow sat on a branch where schedules never fire, and a collector stamped a source value no filter knew. Nothing reported an error. I fixed each one and now checks reachability, not job status, with per-type counts in the run summaries.

Problem 2

A 48-day lag and a 429 storm

Yargıtay publishes decisions about 48 days late, so a 30-day window looked busy and found nothing; daily passes now look back 90 days and the weekly pass 180. One run logged 3,289 rate-limit refusals, most of them re-fetching decisions already indexed. One index lookup per result page, a global back-off that widens after every 429 and a checkpoint per chamber let the pass finish.

Problem 3

Answers must follow the current law

A repealed article kept appearing in answers because the article rows came from a one-off import that nothing refreshed, and the legislation catalog itself ran about eight days behind the Official Gazette. A daily job now rewrites articles from consolidated texts, a collector reads the Gazette directly, and cited provisions are checked before the model runs. Case numbers the guard cannot find in the named chamber are removed, not just flagged.

Built with
ReactNode.jsAzure OpenAIAzure AI SearchCosmos DBPythonDocker