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
- Retrieve your chunks as usual.
-
Send each chunk to
POST /v1/inspectwithsource: "retrieved_document". Content is limited to 4096 bytes per call, so inspect chunk by chunk. -
Read
decision(revieworno_findings). Optionally opt in toenforce: truewithpreset: "rag"to get a stop recommendation. - Apply it in your own code: drop the chunk, quarantine it, or send it to a person. Only then build the prompt.
-
If the call fails (HTTP 503
detector_failed, 413payload_too_large, 429rate_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
-
enforcedefaults tofalse. Without it the response has noenforcementfield (ADR 0047). -
presetonly chooses the rule table and does nothing unlessenforceistrue. Withrag, a finding in aretrieved_documentgivesblock; a finding in any other source givesallow(ADR 0048). Findings, scores,decisionand errors are identical across presets. -
ANANZI never blocks anything in your application.
blockis a value you read; your code does the blocking. -
Send
enforceandpresetonly to an API at contract version 0.6.0 or later; older deployments answer with HTTP 400invalid_request(API changelog).
What this does not guarantee
- No prevention. Inspection flags text; it does
not stop it. A
blockthat your code ignores blocks nothing. -
allowandno_findingsdo not mean safe. They mean the requested checks completed and found nothing under the current rules. There is nosafevalue (ADR 0005). - Detector limits.
secretsmatches the published rule list, so a credential in a format outside it is not found.prompt_injectionis 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_truncatedistrueano_findingscovers only the inspected prefix. - Fail-closed 503 for
prompt_injectionwhile no model is served. Requestingprompt_injectiontoday returns HTTP 503detector_failed, neverno_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 carriesenforcement. - 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).