Skip to content

Technical article RAG · retrieved_document Pre-MVP · ADR 0028

Inspect retrieved documents before the model sees them

A retrieval step pulls text your team did not write into your prompt. ANANZI flags text that looks like prompt injection or carries a credential so your app can decide what to do with it before the model reads it. Detection, not prevention. This article shows the call, a real request and response, and, in its own section, what inspection does not guarantee.

Scope notice: serving clearance is refused under ADR 0028 (#117) and no prompt_injection model is served. That check is experimental and, on this build, fails closed. The check that runs today is secrets (secrets-rules, version mvp-0). The classifiers are static, pretrained model versions; they do not learn from your traffic. Nothing here is a price or a service-level promise.

The pattern

  1. Retrieve your chunks as usual.
  2. Send each chunk to POST /v1/inspect with source: "retrieved_document". Content is limited to 4096 bytes per call, so inspect chunk by chunk.
  3. Read decision (review or no_findings). Optionally opt in to enforce: true with preset: "rag" to get a stop recommendation.
  4. Apply it in your own code: drop the chunk, quarantine it, or send it to a person. Only then build the prompt.
  5. If the call fails (HTTP 503 detector_failed, 413 payload_too_large, 429 rate_limited), treat the chunk as not inspected and leave it out of the prompt. Retry 503 and 429 with backoff.

For the wider RAG integration limits, see the RAG use case. This article covers the call and its guarantees.

The source label matters because a retrieved document is third-party content your app may act on. Setting it lets the recommendation differ from the one for text the user typed themselves (ADR 0047).

A real request and response

The request below uses the AWS documentation sample key, the same input as the quickstart, with the source set to retrieved_document and the opt-in fields added. Use checks: ["secrets"] today: it is the check that completes on this build.

curl -fsS http://localhost:5150/v1/inspect   -H 'content-type: application/json'   -H "Authorization: Bearer ${ANANZI_API_KEY}"   -H 'Idempotency-Key: rag-chunk-1'   -d '{
    "content":"AKIAIOSFODNN7EXAMPLE",
    "source":"retrieved_document",
    "checks":["secrets"],
    "enforce":true,
    "preset":"rag"
  }'

The response has the body shape documented in the quickstart, plus enforcement because enforce was true. The body is shaped like the quickstart's, not a captured run (request_id is elided). The matrix test preset_matrix_for_source in classify.rs asserts that this source, preset and finding give block.

{
  "request_id": "…",
  "decision": "review",
  "findings": [
    {
      "category": "secrets",
      "detector": "secrets-rules",
      "version": "mvp-0",
      "score": null,
      "severity": "high"
    }
  ],
  "enforcement": "block",
  "usage": { "units": 1 }
}

Here decision says the text needs review and enforcement says what to do with a retrieved document: block. For benign text the same call returns decision: "no_findings" with an empty findings list and enforcement: "allow". Reuse the Idempotency-Key when you retry the same chunk; a second success does not add a charge.

Enforcement is opt-in, and a recommendation

  • enforce defaults to false. Without it the response has no enforcement field (ADR 0047).
  • preset only chooses the rule table and does nothing unless enforce is true. With rag, a finding in a retrieved_document gives block; a finding in any other source gives allow (ADR 0048). Findings, scores, decision and errors are identical across presets.
  • ANANZI never blocks anything in your application. block is a value you read; your code does the blocking.
  • Send enforce and preset only to an API at contract version 0.6.0 or later; older deployments answer with HTTP 400 invalid_request (API changelog).

What this does not guarantee

  • No prevention. Inspection flags text; it does not stop it. A block that your code ignores blocks nothing.
  • allow and no_findings do not mean safe. They mean the requested checks completed and found nothing under the current rules. There is no safe value (ADR 0005).
  • Detector limits. secrets matches the published rule list, so a credential in a format outside it is not found. prompt_injection is experimental, a static pretrained model; it will miss some attacks and flag some harmless text. Published counts come from one small corpus and are not a launch claim: see the evaluation methodology and results and the model comparison table.
  • Truncation. The model reads 512 tokens, special tokens included. Longer text is right-truncated, and when prompt_injection_truncated is true a no_findings covers only the inspected prefix.
  • Fail-closed 503 for prompt_injection while no model is served. Requesting prompt_injection today returns HTTP 503 detector_failed, never no_findings, and returns no partial findings for the other checks on that call. Handle it as "not inspected"; see Errors and handling detector failures. A failed call never carries enforcement.
  • Source-aware policy is not here. Presets pick among fixed tables; you cannot write your own per-source rules.
  • No latency promise. The only figure is a target, not an SLA: p50 at most 100 ms and p95 at most 500 ms, warm, tokenization and inference only, unmeasured at 512 tokens (ADR 0039).