Kenya legal grounding contract: 8-rule retrieval gate replaces open-ended knowledge fallback

Davemaina1 replaces "answer based on your legal knowledge" with a hard retrieval requirement: the model must call a tool before citing any Kenyan statute or case, and training-data citations are banned outright. The honesty contract and the dual-tool retrieval pattern are both portable, even if the Kenya corpus isn't.

searchcompliance

The system-prompt change (7244c0be) is explicit about intent. Before: one line saying to answer from legal knowledge when no documents exist. After: 8 rules stating the model must call search_kenya_law or search_legal_authority_web before any legal authority claim, may only cite what retrieval returns, must surface corpus-vs-web conflicts, must explicitly admit when both tools return nothing, and must never invent or paraphrase a citation. The "violating this is worse than admitting you don't know" framing is pointed - it's there because hallucinated legal citations are the product's single worst failure mode. The contract was written before the tools existed, so the model would refuse rather than hallucinate during the gap.

The tool implementation (07e1243e) adds two tools. search_kenya_law uses ChromaDB with @xenova/transformers v2 (Xenova/all-MiniLM-L6-v2, 384-dim, mean-pool, normalized), a lazy-cached embedder and collection, and returns 400-char snippets with a distance > 0.6 weak-result note. The east_africa jurisdiction filter applies via a ChromaDB where clause; the narrower kenya filter is intentionally skipped to avoid silently dropping chunks that predate the metadata field. search_legal_authority_web is Tavily search restricted to 12 trusted Kenyan/East African legal domains; it never throws. New deps: chromadb ^3.4.3, @xenova/transformers ^2.17.2, CHROMA_DB_PATH and TAVILY_API_KEY in .env.example.

83f72e57 upgrades NormalizedResult from three fields to eleven. The honesty contract requires the model to distinguish binding from persuasive authority and prefer newer law - the original { text, source?, jurisdiction? } shape couldn't support that. The new shape adds title, url, source_archive, type, court, year, binding_in_kenya, citation, and snippet. Year falls back to regex extraction from date if the year field is absent. The trusted-domain allowlist expands from 12 domains to roughly 25, organized into tiers: primary authority, major regulators with published decisions, and specialist oversight bodies.

One caveat: the Node-local ChromaDB + ONNX stack introduced here gets replaced by a Python sidecar in a later commit cluster. Pulling these commits means taking a dependency that Davemaina1 themselves abandoned. The honesty contract and the domain allowlist are the portable pieces; the retrieval implementation is not.

So what Worth a look if your fork has jurisdiction-specific legal grounding ambitions. The honesty contract is verbatim-portable and the dual-tool pattern (local corpus + domain-allowlisted web search) is a clean template regardless of jurisdiction. Skip the Node-local retrieval code - the fork itself replaced it. Evaluate whether the domain allowlist logic suits your target jurisdiction before importing it.

View this fork on GitHub →

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

Commits in this thread

3 commits from Davemaina1/iroh_, oldest first. Source extracted verbatim from the harvested git log.

SHA Subject Author Date
7244c0be feat: add Kenyan legal authority grounding contract to system prompt Davemaina1 2026-05-13 ↗ GitHub
commit body
Replaces the open-ended "answer based on your legal knowledge" line with
an 8-rule honesty contract that:
- Requires retrieval via search_kenya_law (local corpus) and
  search_legal_authority_web (approved domains) before citing any
  Kenyan statute, case, regulation, or guidance
- Prohibits citing Kenyan legal authority from training data
- Requires surfacing corpus-vs-web conflicts and preferring newer authority
- Mandates an explicit "no results" admission when both tools come up empty
- Bans invented or paraphrased citations outright
- Flags EA Court of Appeal cases (pre-1977) as persuasive, not binding
- Directs users to kenyalaw.org / relevant regulator for out-of-corpus
  authorities

Retrieval tools (search_kenya_law, search_legal_authority_web) are not yet
registered - contract is placed ahead of implementation intentionally so
the model refuses rather than hallucinates if a retrieval gap occurs.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
07e1243e feat: add Kenya Law RAG and trusted web search tools Davemaina1 2026-05-13 ↗ GitHub
commit body
Implements two retrieval tools that ground Iroh's legal responses in
authoritative Kenyan sources rather than training-data recall:

- search_kenya_law: ChromaDB semantic search over the Kenya Law corpus
  using Xenova/all-MiniLM-L6-v2 embeddings (384-dim, mean pool,
  normalized). Lazy-cached embedder and collection. east_africa
  jurisdiction filter applied via where clause; kenya filter omitted
  to avoid silently dropping chunks that predate the metadata field.
  Returns 400-char snippets with distance; notes weak results (>0.6).

- search_legal_authority_web: Tavily search restricted to 12 trusted
  Kenyan/East African legal authority domains (kenyalaw.org,
  parliament.go.ke, judiciary.go.ke, etc.). Never throws - all
  failures surface as { results: [], note }.

Both tools registered in TOOLS[] and dispatched in runToolCalls.
chromadb and @xenova/transformers added as dependencies.
CHROMA_DB_PATH and TAVILY_API_KEY documented in .env.example.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
83f72e57 Fix normalizer metadata projection; verify and expand domain allowlist Davemaina1 2026-05-13 ↗ GitHub

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-378.md from inside the repo you want the changes in.

⬇ Download capture-thread-378.md