Swiss court decisions and statutes wired as LLM tools via OpenCaseLaw

beniauer added a grounding layer for Swiss legal questions: five LLM tool calls that hit the OpenCaseLaw public API instead of relying on model recall, with explicit instructions in the system prompt to never invent BGE docket numbers or SR statute references. Worth a look if you have any Swiss-law use case.

searchknowledge-management

backend/src/lib/swissCaselaw.ts is a thin REST client for mcp.opencaselaw.ch/api (base URL overridable via OPENCASELAW_BASE_URL). It covers three sources: ~956k court decisions across federal and cantonal courts, statutes from Fedlex and 26 cantonal collections, and OnlineKommentar.ch commentaries. No auth required. Each call uses a 15-second abort timeout; error handling is defensive but there's no retry.

Five tool definitions land in chatTools.ts: search_swiss_caselaw, read_swiss_decision, search_swiss_laws, read_swiss_law, search_swiss_commentaries. search_swiss_caselaw supports FTS5 syntax - keywords, quoted phrases, AND/OR/NOT, prefix wildcards - and filters on court code, canton, language, date range, chamber, and decision type. Both search and fetch return citation_string_de/fr/it and canonical_url for inline citation.

The system prompt gains a SWISS LAW LOOKUP section that instructs the model to prefer these tools over training-data recall for any Swiss question, to quote citation_string and canonical_url verbatim, and to report no-result rather than fabricating. The <CITATIONS> block stays reserved for user-attached documents; OpenCaseLaw quotes go inline.

The frontend adds a /caselaw search page with three tabs (decisions, laws, commentaries) and a normalized caselawRouter on the backend. One split to be aware of: the /caselaw Express route isn't mounted in index.ts until a separate commit in the rebrand topic, so pulling this commit alone gives you the chat tools but not the standalone search page backend.

So what Worth a close look if Swiss law is in scope. The anti-hallucination discipline is applied carefully - the tool descriptions say "cite these verbatim" and the system prompt explicitly forbids inventing case numbers. The main operational risk is dependence on a single unauthenticated public API with no caching or retry; a rate limit hit or outage degrades silently to empty results. Low value for non-Swiss jurisdictions.

View this fork on GitHub →

Spotted something wrong? Or know the PR text has fresher detail than the writeup above?

Commits in this thread

1 commit from beniauer/michi, oldest first. Source extracted verbatim from the harvested git log.

SHA Subject Author Date
24ed7ade feat: Swiss case law lookup via OpenCaseLaw Benjamin Auer 2026-05-22 ↗ GitHub
commit body
Ground legal answers in primary sources instead of model recall.

- swissCaselaw.ts: REST client for the OpenCaseLaw API (decisions, statutes,
  commentaries; no auth required).
- chatTools.ts: register search/read tools so the assistant cites real
  decisions with canonical URLs instead of inventing case numbers.
- Dedicated /caselaw search page + sidebar nav for direct lookups, with
  results linking to the official source.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

Capture this thread into my fork

Download a single Markdown prompt that tells Claude how to port every commit above into your working tree — adapting paths and structure to match your repo. Run it via claude -p < capture-thread-552.md from inside the repo you want the changes in.

⬇ Download capture-thread-552.md