Citation-guarded retrieval over 22M Taiwan court judgments and administrative interpretations
Copy the AI prompt to install this server into Claude Code, Cursor, or another agent β or use 1-click editor setup below.
π‘ Paste into ~/Library/Application Support/Claude/claude_desktop_config.json (macOS) or %APPDATA%\Claude\claude_desktop_config.json (Windows)
twlegalrag)English γ» ηΉι«δΈζ γ» ζ₯ζ¬θͺ
Source-available CLI for semantic Taiwan legal judgment retrieval, powered by Legal Detective's 22M-judgment retrieval infrastructure.
Taiwan Legal RAG CLI retrieves Taiwan court judgments from Legal Detective's public TLR endpoint and packages them for use with your own AI tools. It does not generate legal advice, does not call any LLM, and does not guarantee semantic faithfulness of third-party model outputs. Its built-in citation check only verifies whether cited judgments belong to the retrieved bundle.
This is not a generic keyword judgment search tool. It connects to the TLR retrieval service that Legal Detective has been building for a long time:
case_history (v1.1) β when reading a judgment's full text,
the database-recorded upper/lower instances are attached (including a flag
for δΈ»ζε«γε»’ζ£γ, i.e. the holding was vacated on appeal). You can see
whether a judgment has been vacated by a higher court before citing it.
Absence of an upper-court record only means the database has no record; it
does not mean the judgment is final.get_legal_reference
(2026-08, hosted MCP) β look up an administrative interpretation (ε½ι) by
its issuing serial number (e.g. ε°θ²‘η¨
第881945861θ) and get its full text
plus a lifecycle status (verified-active / unverified / repealed /
no-longer-applied / superseded). Verify existence and validity before citing
an interpretation; a miss explicitly states that not found does not mean
the interpretation does not exist. Interpretations and judgments are
strictly separated: never mixed in one ranking, and never to be cited as
court reasoning. See docs/mcp-anchor.md.search_legal_references (2026-08,
hosted MCP) β natural-language topic search over the same interpretation
corpus (optional agency / source-kind filters). Returns candidates with the
same lifecycle status field, a similarity score, and an excerpt β and
deliberately performs no relevance judgment: the calling model must
read each candidate, judge relevance itself, and verify text + validity via
get_legal_reference before citing. The pair closes the loop against
serial-number guessing: search finds real serials, exact lookup verifies
them.allowed_citations whitelist (only judgments whose
reasoning text was actually read in), unread_candidates markers (judgments
whose reasoning was not read must not be cited as authority), verification
instructions written into every bundle (including opinion-layer self-check),
plus a bundle-level citation check on the CLI side. The whole design targets
the most painful hallucination pattern in legal AI: real case number,
fabricated holding. Ordinary retrieval tools stop at handing data to the
model; here, citation discipline is part of the data format itself.Another common approach is to proxy the Judicial Yuan / law database websites' built-in search in real time. The two serve different purposes and can complement each other:
| Official-site wrapper | Taiwan Legal RAG | |
|---|---|---|
| Search | official site keyword search | semantic retrieval over a self-built 22M-judgment corpus; finds conceptually similar cases even with different wording |
| Citation protection | usually none | read-whitelist + verification instructions + citation check |
| Docket lookup | as provided by the site | exact lookup; on a miss it explicitly says not to speculate |
| Appeal chain | trace case by case yourself | case_history attached, with vacated flags |
| Availability | subject to site WAF / redesigns; often needs a local browser to pass challenges | hosted endpoint, zero local setup |
| Freshness | official site is real-time | for very recently published decisions, check the official site |
The wrapper's strength is real-time official-source access; this tool's strength is semantic retrieval quality and citation discipline.
Unlike keyword-only legal search tools, Taiwan Legal RAG CLI connects to a production semantic retrieval backend built on 22M+ Taiwan court judgments, enabling fuzzy concept-level search while keeping model weights, infrastructure, and private indexes server-side.
(Wording note: what is published here is the CLI, not the model or the vector store; the backend retrieval service, model weights, and private indexes stay server-side and are not published with this tool.)
Does: retrieve judgments with natural language β get a structured listing, judgment reasoning excerpts, and citation links β package them into a bundle for your own AI; and run a bundle-level citation check on any AI-generated answer.
Does not: this tool calls no LLM, generates no legal opinion, and endorses no model output. Answers are produced by the AI you choose (ChatGPT / Claude / Gemini / a local model).
check is a bundle-level, best-effort string check. It only verifies:
All of these require reading the full judgment text β which is why bundles
include judgment excerpts and verification instructions that require the
downstream model to verify on its own. pass only means "the cited numbers
match the bundle's identity list"; it does not mean "the legal reasoning is
correct" or "the quote really comes from that judgment." Also, check only
compares against bundle content, not the entire Legal Detective database β
if you later open full judgment texts yourself and rewrite the answer, check
still only sees the excerpts originally packed.
Depends only on httpx / typer / rich. No LLM packages or keys needed β
this tool does not call LLMs.
A pack bundle contains query, each judgment's citation_id (J1, J2, ...),
citation_text, citation_url, doc_id, the Layer-1 listing,
fulltext_excerpt (an excerpt of the judgment's reasoning, length-capped),
case_history (database-recorded appeal chain, v1.1), allowed_citations,
and a verification_instructions block that explicitly requires the
downstream model to cite only in-bundle judgments and to mark unsupported
propositions as unverified. An AI USE NOTICE is also printed to stderr.
Since v1.1, verification_instructions additionally includes an
OPINION-LAYER SELF-CHECK: after answering, the downstream model must go
back and verify that (a) every holding attributed to a judgment actually
appears in that judgment's excerpt (not another judgment's, not inferred);
(b) outcome directions (win/lose/vacated/dismissed/remanded) are not reversed;
(c) judgments shown as vacated in case_history are not cited as currently
valid holdings. This complements check's bundle-level number check β a real
case number does not make the attributed holding real, and opinion-layer
verification can only be done by the model that read the text; these rules
write that obligation into every bundle.
allowed_citations is the whitelist of citable judgments and only contains
judgments whose reasoning text was actually read in. The CLI's pack reads
every judgment it returns, so the two always match. For the hosted Remote MCP
search_bundle (/v1/pack), when read_top < max_results, only the top
read_top judgments are read in full; the rest remain listed in judgments
for browsing but are moved to unread_candidates (not authority; must not be
cited as court reasoning). See docs/mcp-anchor.md.
By default the CLI talks to the public endpoint https://tlr.dr-lawbot.com,
no key required. If the service operator issues you an API key, put it in an
environment variable or ~/.twlegalrag/config.toml (git-ignored β never
commit it):
First, what never passes through the TLR server:
What does travel over the network, and you should understand:
https://tlr.dr-lawbot.com) to fetch judgments.twlegalrag/faithful/ is a set of zero-dependency pure functions (standard
library re + unicodedata only). Given the answer text and the bundle's
judgment excerpts, it returns pass / needs_review / fail. It is
deliberately conservative: when unsure it returns needs_review rather than
fail to keep false alarms low. It calls no LLM and touches no database;
it is deterministic string analysis.
β οΈ This directory is a snapshot of internal code; some functions in it
(e.g. check_party_as_court / run_all_checks) are not used by the CLI.
Their presence does not mean the CLI can do opinion-layer / semantic
verification β the CLI uses only two bundle-level checks. Do not read the file
list as a feature list. See twlegalrag/faithful/VENDORED.md.
This CLI is one way to use the TLR retrieval service. The same backend
tlr.dr-lawbot.com also supports plugging judgment search directly into your
AI tools via Remote MCP. Both use the same MCP endpoint
https://tlr.dr-lawbot.com/mcp; OAuth completes automatically on connection
(dynamic registration, no API key application or setup needed):
https://tlr.dr-lawbot.com/mcp.https://tlr.dr-lawbot.com/mcp.skills/tw-legal-rag/.
Copy that folder into your project's .claude/skills/ and Claude will run
this CLI's pack subcommand whenever a question involves Taiwan case law,
citing only citation_ids that exist in the returned bundle. Setup notes
and Windows caveats are in the skill's SKILL.md.
The Remote MCP surface currently has five tools: search_bundle,
search_judgments, get_judgment_fulltext, plus get_legal_reference and
search_legal_references added in 2026-08 (exact lookup and semantic search
over administrative interpretations, see
docs/mcp-anchor.md); the last two are not wired into
this CLI yet.This server is listed in the official MCP Server Registry
as io.github.aa0101181514/tw-legal-rag.
Whether you go through the CLI, MCP, or the Claude Code skill, answers are generated by your own AI; this service only provides judgment content and verifiable citation links.
The judgment corpus, embeddings, and retrieval logic live server-side and are not in this repo. This CLI is the published client and citation-check tool.
This tool is an analysis aid, not legal advice, and not a lawyer. Always read the full text of cited judgments yourself. Judgments obtained through the API are Taiwan's publicly available court decisions; you are responsible for your own use.
Elastic License 2.0 (ELv2) from v2.0.0. Free to use, copy, modify and redistribute β including commercial and internal-business use β with two limits: you may not offer the software itself to third parties as a hosted or managed service, and you may not remove license/notice protections. Versions up to v1.2.2 remain MIT.
The hosted API and the judgment corpus were never covered by the code
license β see TERMS.md. Project names and logos are not licensed β
see TRADEMARK.md. This project does not accept external pull
requests (single-author licensing policy) β see CONTRIBUTING.md.
mcp-name: io.github.aa0101181514/tw-legal-rag
Showcase your server listing on GitHub or your project documentation. Embed this dynamic SVG badge to highlight official listing status and live engagement.
[](https://allmcps.com/mcp/tw-legal-rag)<a href="https://allmcps.com/mcp/tw-legal-rag"><img src="https://allmcps.com/api/badge/tw-legal-rag?style=directory" alt="Tw Legal Rag on AllMCPs" /></a>