Noul questions sent to TypeSafe for each of those passages, the thresholds in route()
that label each one, the prompt assembled from separate evidence and conflict blocks, and
the answers claude-sonnet-5 writes from it.
Setup
Run in Colab
Runs as published without an API key.
Python file
This page as one .py file, to run locally.
Open in playground
Edit one request and run it live. Needs a TypeSafe account.
uv run classifying_rag_passages.py installs the dependencies for you.
The code replays saved answers, so it runs as published without an API key. To change a
request, set TYPESAFE_API_KEY, ANTHROPIC_API_KEY and OPENAI_API_KEY; in Colab, add
them in the Secrets panel. We use Jev to score each retrieved passage, OpenAI to embed the
corpus for the search step, and Claude to write the final answer out of whatever survives
the scoring.
The numbers here came out of jev-1.14.0 and claude-sonnet-5 on 2026-11-03.
Load the docs corpus
The corpus filecorpus.json holds 81 passages. We copied 80 of them straight from the
Supabase auth docs at commit 2440b06, one passage per heading, verbatim and used under
Apache 2.0:
https://github.com/supabase/supabase/tree/2440b06/apps/docs/content/guides/auth
Each passage carries id, title, text and source_type, and every request sends all
four. Near-misses fill the set. Rotation, expiry, sessions and signing keys each get their
own page, and those pages read alike. Refresh-token rotation and JWT signing-key rotation
are different things described in nearly the same words.
We wrote the last one ourselves, forum-injection, marked community_forum: it reads as
an ordinary forum answer until its final paragraph, which is an instruction aimed at the
model.
We also wrote two of the six queries to state a premise the docs contradict, so the
injection and conflict routes both have something to catch.
Retrieve the top passages
Rank the passages by cosine similarity over embeddings, usingtext-embedding-3-small at
256 dimensions, and keep the best TOP_K = 12 for each query. Short vectors keep the
shipped cache small, and the embedding calls are cached with everything else, so the
vectors travel inside classifying_rag_passages_cache.json.
forum-injection, ranks 1st at 0.584.
The passage that refutes the premise, sessions-01, ranks 7th at 0.509. All 12 scores
fall between 0.584 and 0.455, a spread too narrow to separate the passage that corrects
the query from the one trying to hijack the answer.
Ask four questions about each passage
Put the query and one passage in the state together, so every question is about the pair rather than the passage alone. Shape:Noul questions, and what each answer drives:
is_relevant: the relevance floor.contains_answer_evidence: include, or drop.contradicts_query_premise: promotes to the conflict block.contains_prompt_injection: excludes outright.
Route each passage in code
Every answer comes back as a probability, and there are plenty of ways to turn four of them into one decision. A plain run of comparisons worked here. Test the four probabilities against their thresholds in a fixed order and stop at the first match. That match labels the passage, and the label decides what happens to it: evidence in the prompt, a conflict in the prompt, or dropped. The tests, in order:contains_prompt_injection > 0.70-> excludecontradicts_query_premise > 0.70-> conflicting_evidenceis_relevant < 0.45-> excludecontains_answer_evidence > 0.55-> include- otherwise exclude
We picked these four numbers for this corpus. Treat them as a starting point, not
defaults. Moving one is cheap:
THRESHOLDS holds all four and route() reads only the
stored answers, so re-routing every passage costs no API calls.sessions-01 at 0.92 and sends it to the
conflict block. Relevance reads 0.58 and answer evidence 0.78, so without the
contradiction test ahead of them it would have landed in the accepted block.
Similarity ranked forum-injection first and its relevance clears the floor at 0.60. The
injection score of 0.98 is what drops it.
Nothing reaches the prompt as evidence, which is right for a question built on a false
premise. Below, the same table for a query the docs do answer.
forum-injection is excluded again at 0.98.
The injection question is a filter, and only one. A passage that scores under the
threshold still reaches the prompt, so the generator prompt has to treat every passage as
untrusted text regardless of its score. Nothing here is a security boundary.
One request per passage, so cost scales with k. Nothing batches passages into one
request, because each question is about one pair.
Build the prompt from the accepted evidence
Jev scores the passages and the routing labels them. An LLM still writes the answer, hereclaude-sonnet-5. Keep accepted and conflicting evidence in separate blocks.
Two blocks let the answer push back. Merge them into one and the generator has no way to
tell a passage that answers the query from one that denies its premise.
forum-injection and its injected instruction.
sessions-01 on refresh tokens never expiring rather than inventing a 30-day setting.
The second had 3 accepted passages and no conflict, and cites all three. Nothing of the
injected instruction reaches the text.
Compare the six queries



