Dike logoDocs

The primary vulnerability of Large Language Models in the legal domain is citation hallucination: inventing plausible-sounding statute numbers, mixing up article provisions, or citing overruled precedent.

Dike eliminates this risk at the infrastructure layer through its Grounding Verification Engine.

Rendering diagram...

1. Closed-World Citation Constraint

When you send a query to POST /v1/reason, the system constructs an ephemeral, closed-world context containing the top_k top-ranked legal chunks from the retrieval engine.

The LLM is prompted under strict syntactic constraints:

  1. It may only state legal assertions that are directly supported by the provided context.
  2. Every legal claim must be explicitly followed by a reference tag identifying the source: [[REF:canonical_id#article_no]].
  3. It must not extrapolate, invent statute numbers, or cite external legal memory.

2. Real-Time Token Interception & Validation

During generation (both synchronous and SSE streaming), the Dike gateway monitors the token stream:

The Set Membership Check

Let C be the candidate set of valid (canonical_id, article_no) tuples retrieved for this query:

Valid(ref) = (ref.canonical_id, ref.article_no) ∈ C
  • If Valid(ref) == true:
    • The token is verified.
    • The gateway assigns a sequential marker index (1, 2, 3...).
    • The raw tag [[REF:eg-leg-1948-131#163]] is rewritten to [1].
    • The full metadata and snippet of the source article are added to the citations array.
  • If Valid(ref) == false (Hallucination):
    • The token is immediately stripped from the text output.
    • The hallucination is logged in internal metrics.
    • grounding.dropped_unverified_refs is incremented.

3. Grounding Telemetry in Responses

Every /v1/reason response returns precise grounding metadata:

{
  "answer": "يلتزم المستأجر بسداد الأجرة في المواعيد المتفق عليها [1]...",
  "citations": [
    {
      "marker": 1,
      "canonical_id": "eg-leg-1948-131",
      "article_no": "586",
      "citation_string": "المادة 586 من القانون المدني رقم 131 لسنة 1948",
      "snippet": "يجب على المستأجر أن يقوم بوفاء الأجرة في المواعيد المعينة...",
      "verified": true
    }
  ],
  "grounding": {
    "retrieved": 12,
    "used": 1,
    "dropped_unverified_refs": 0
  }
}
  • grounding.retrieved: Total legal chunks supplied to the model.
  • grounding.used: Count of verified citations cited in the final answer.
  • grounding.dropped_unverified_refs: Number of fabricated citation markers intercepted and stripped by the hallucination guard.

4. Weak Grounding & Refusal Sentinels

If the model is asked a question that cannot be conclusively answered by the indexed corpus:

  1. Weak Grounding (X-Dike-Grounding: weak):
    • If the answer text contains 0 verified citations (grounding.used: 0), Dike automatically attaches the HTTP header X-Dike-Grounding: weak.
    • Your frontend application should use this header to render a disclaimer or warning badge.
  2. Explicit Refusal Sentinel:
    • Rather than inventing an answer, the model will output an explicit refusal sentinel (e.g. "لا أجد سنداً قانونياً كافياً في المصادر المفهرسة للإجابة على هذا السؤال").

Next Steps

On this page