Skip to content

DocsExamples

4 min read · updated

RAG: answer or abstain

Before a retrieval pipeline answers, check whether the passages it found answer the question; answer when decisio is sure, and say so when they do not.

The script sends the question and the passage as one text and acts only on a certified answer:

Figure · How to use it

The model judges the input; your code chooses the action.

  1. InputA question and passage
  2. QuestionDoes the passage answer the question?
  3. Typed answerAn answerability key and probabilities
  4. Your codeAnswer from the passage, explain what is missing or ask for review.

The answer is under answers.answered. Check the certificate required by your application before automating the action.

Source: this recipe’s question and application policy. No model result is illustrated here.

Save the complete caller as rag-gate.py and run it with Python 3.12 or later. Set DECISIO_BASE_URL to your server, or leave the local default. Until you register and certify this question, the caller sends answers to review.

python
import json
import os
import urllib.error
import urllib.request
QUESTION = {
"type": "choice",
"instructions": "Does the passage answer the question?",
"criteria": {
"yes": "The passage answers the question",
"partly": "It answers only part of it",
"no": "It does not answer it"
}
}
BASE_URL = os.environ.get("DECISIO_BASE_URL", "http://127.0.0.1:8000").rstrip("/")
TIMEOUT = 15
REVIEW = "to a larger model or a person"
def route(text):
request = urllib.request.Request(
BASE_URL + "/v1/systemone",
data=json.dumps({"state": text, "questions": {"answered": QUESTION}}).encode(),
headers={"Content-Type": "application/json"},
)
try:
with urllib.request.urlopen(request, timeout=TIMEOUT) as response:
answer = json.load(response)["answers"]["answered"]
if not isinstance(answer, dict) or answer.get("type") != QUESTION["type"]:
return REVIEW
if not (answer.get("choice") in QUESTION["criteria"]):
return REVIEW
# A gold certificate is about correctness; agreement alone is insufficient.
if (answer.get("certified") is True
and answer.get("certificate_kind") == "gold"
and isinstance(answer.get("certificate"), str)
and answer["certificate"]):
return {"yes": "answer from the passage", "partly": "answer, and say what is missing", "no": "say it is not in the documents"}[answer["choice"]]
return "to a larger model or a person"
except (urllib.error.URLError, TimeoutError, OSError, ValueError, KeyError, TypeError):
return REVIEW
if __name__ == "__main__":
print(route("Question: How long is the warranty?\nPassage: Every product comes with a two-year warranty from the date of purchase."))
Output
to a larger model or a person

Good fit

  • A retrieval step that returns passages, and questions your users ask again and again.
  • Labelled pairs of a question and a passage, to certify from.

Not a good fit

  • Writing the answer itself: decisio reads and decides, it does not write.
  • Questions that need reasoning across many documents at once.

One choice question about the text: does the passage answer the question, partly, or not. Put the user’s question and the passage in the text, as the script does.

Teach the question from labelled pairs, and certify it at your error target.

Send at least 118 labelled question and passage pairs. The server holds back half to certify, and a 5% certificate needs 59 of those. More examples certify a larger share.

Prepare rag-gate-labels.jsonl with one JSON object per line, containing state and answer. Use real inputs and labels chosen by a person; each answer is one of the question’s option keys. The code below builds complete requests using the same question as the caller.

python
import json
import os
import urllib.request
QUESTION = {
"type": "choice",
"instructions": "Does the passage answer the question?",
"criteria": {
"yes": "The passage answers the question",
"partly": "It answers only part of it",
"no": "It does not answer it"
}
}
# One JSON object per line: state and the answer chosen by a person.
with open("rag-gate-labels.jsonl", encoding="utf-8") as source:
rows = [json.loads(line) for line in source if line.strip()]
examples = [
{"request": {"state": row["state"], "questions": {"answered": QUESTION}},
"answer": row["answer"]}
for row in rows
]
body = {"id": "rag-gate", "examples": examples, "certify": {"alpha": 0.05}}
base_url = os.environ.get("DECISIO_BASE_URL", "http://127.0.0.1:8000").rstrip("/")
request = urllib.request.Request(
base_url + "/v1/tasks", data=json.dumps(body).encode(),
headers={"Content-Type": "application/json"},
)
# Registration reads all your examples; allow more time than an ordinary decision.
with urllib.request.urlopen(request, timeout=300) as response:
record = json.load(response)
print(json.dumps(record.get("certificate"), indent=2))

Needs the reader’s own human-labelled JSONL file.

Save the registration script beside the labels file and run it with Python. Registration replaces a task of the same id. Check the returned certificate: a null threshold means no answer can be certified.

Certify answers runs this call on a server, with its answer. To let the server decline on its own, add a “can’t tell” option and an abstention threshold (Certify answers).

The caller acts only when certified is true and certificate_kind is gold, with a certificate id. A learned table’s agreement certificate measures agreement with the model, so it goes to review in this recipe.

  • A certified yes answers from the passage; partly answers with the missing part stated; no says it is not in the documents.
  • Everything else goes to a larger model or a person.
  • When your documents or your users’ questions change, certification is suspended until you certify again (Watch for drift).
  • 82.7% right on SciFact, does the evidence support the claim, and 88.7% on BoolQ, yes or no over a passage, on Gemma 4 31B, untaught, in decisio's 1,400-item suite: one RTX PRO 6000, vLLM 0.30.0, 2026-10-04 (its evaluation card, section 7.2).
  • Those measure the reading, not a whole retrieval pipeline: no end-to-end run of this gate is published.