aa0101181514/tw-legal-rag
台灣法律 MCP 伺服器 + CLI(免費、免註冊、免 API key):2,250 萬筆裁判書、行政函釋、憲法法庭裁判,附引用查核。Free Taiwan legal MCP server for Claude/ChatGPT/Codex — bring your own LLM, retrieval-only.
TL;DR
Taiwan Legal RAG is a command‑line tool that lets you query a public, server‑hosted semantic search service containing ~22 million Taiwanese court judgments, statutes and administrative rulings. It returns the matching documents as a bundle that you can feed to any LLM (ChatGPT, Claude, Gemini, a local model, etc.) and it also provides a lightweight, deterministic citation‑check that verifies the LLM’s answer only cites material that is actually present in the bundle.
What it is
- Type: Open‑source Python CLI (installable via
pip install twlegalrag). - Purpose: Retrieve Taiwanese legal texts (court judgments, statutes, administrative interpretations) via natural‑language queries and package the results for downstream AI use.
- Scope: Legal‑retrieval + citation verification; does not run or host any language model, nor does it give legal advice.
Core features
| Feature | What it does | Why it matters |
|---|---|---|
| Semantic (fuzzy) search | Uses a server‑side vector‑based index to find judgments that are conceptually related to your query, not just keyword matches. | Lets you discover relevant cases even when you use different wording. |
| Exact‑case lookup | Precise case‑number lookup with automatic “case not found” handling. | Guarantees you are referencing the correct judgment. |
| Case‑history linkage | Each judgment bundle includes case_history showing appellate relationships and whether a decision has been overturned. |
Prevents citing a judgment that is no longer good law. |
| Law article lookup | Retrieve the current text of statutes, with amendment dates and validity flags. | Gives you the exact statutory wording to cite. |
| Administrative‑rule search | Both exact‑number and semantic search for regulations and interpretive orders. | Covers the full hierarchy of Taiwanese law. |
Bundle creation (twlegalrag pack) |
Packages query, matching judgments, excerpts, URLs, citation whitelist, and verification instructions into a JSON file. | Provides a self‑contained artefact that any LLM can consume safely. |
Citation check (twlegalrag check) |
Deterministic string‑match check that verifies: (1) cited case numbers are in the bundle, (2) cited text actually appears somewhere in the bundle, (3) no out‑of‑bundle citations. | Helps catch “hallucinated” citations before the answer is presented. |
| Health endpoint | Simple twlegalrag health ping to confirm the remote service is reachable. |
Quick sanity‑check for scripts. |
| Zero‑LLM dependency | Only requires httpx, typer, rich. No API keys needed for the public endpoint. |
Easy to install and run in any environment. |
How it works (high‑level flow)
- Search – The CLI sends your natural‑language query to the hosted TLR REST endpoint (
https://tlr.dr-legal.com.tw). The server returns a list of matching judgments with aresult_token. - Full‑text fetch – Using the token, the CLI pulls excerpts (and optionally the full text) for each judgment.
- Pack – All retrieved data are assembled into
bundle.jsoncontaining:querycitation_id/citation_text/citation_urlcase_historyallowed_citationswhitelistverification_instructions(rules for the downstream model to follow).
- Consume – You paste the bundle into your LLM prompt and ask it to answer using only the provided citations.
- Check – After the LLM replies, run
twlegalrag check bundle.json answer.txtto verify that every citation the model used is present and that quoted snippets exist in the bundle.
Who might use it
- Legal tech developers building chat‑bots or RAG pipelines for Taiwanese law.
- Lawyers or researchers who want a reproducible, citation‑safe way to feed case law into LLMs.
- Compliance teams needing to ensure AI‑generated advice references only verified statutes/judgments.
- Educators / students exploring AI‑augmented legal research without handling massive datasets locally.
Limitations & caveats
- The CLI is only a client; the heavy lifting (vector embeddings, index, retrieval) lives on the remote TLR server.
- Citation check is string‑based; it cannot confirm that a quoted passage is from the correct judgment or that the legal reasoning is accurate.
- No personal data or confidential documents are ever sent to the TLR service – only the plain query string.
- The service is free and open, but the backend may log queries for quality analysis; do not submit sensitive information.
- The repository is under Elastic License 2.0 (commercial‑friendly) and does not accept external pull requests.
Quick start example
# Install
pip install twlegalrag
# Find recent cases about overtime pay
twlegalrag search "勞資 加班費" -n 5 --read
# Create a bundle for an AI prompt
twlegalrag pack "車禍對方全責,我可以求償什麼?" -o bundle.json
# After getting an answer from your LLM, verify citations
twlegalrag check bundle.json answer.txt
License & governance
- CLI code: Elastic License 2.0 (free for commercial and internal use, with two restrictions – no re‑hosting the software as a service and must retain the license notice).
- Data & API: Not covered by the code license; usage governed by the separate
TERMS.mdandTRADEMARK.mdfiles. - The project is maintained by a single author (Aaron Huang, founder of Legal Detective / Dr.Legal) and does not accept outside pull requests.
Bottom line
twlegalrag gives you a practical bridge between a massive, up‑to‑date Taiwanese legal corpus and any LLM you choose, while providing a deterministic, open‑source guard against fabricated citations. It’s a genuine, production‑grade tool for legal‑RAG workflows, not just a demo or a curated list.
Related
- Project
- Project
- Project
- Project
- Project