Skip to main content
A model that answers from retrieved sources can still add a claim the sources never make. This example checks a draft against its sources before your user sees it. Use it in a retrieval pipeline, after the answer is written and before it is shown.

How it works

The context is JSON with the user’s question, the sources you retrieved and the draft answer. The keys are yours to choose. One binary decision, grounded, asks whether the sources establish every factual claim in the draft. yes means every fact is stated in the sources or follows directly from them. no means at least one fact is missing from the sources or contradicts them.

Try it

Open this recipe in the playground to run it without an account. The sources there say refunds cover the unused months only. The draft promises a full refund within 14 days, even after a year of use. To run it from your code, set SQWISH_API_KEY as in the quickstart, then send this request:

Act on the answer

A missed unsupported claim usually costs more than a false alarm, so start at 0.7 rather than 0.5. Then check how many drafts that blocks.

Adapt it to your data

It works best on one claim at a time, which is how it was measured. The sample draft makes two claims: that you can cancel any time, and that you get a full refund. For a longer answer:
  1. Split the draft into sentences, and split a sentence again if it makes several claims.
  2. Check each claim against the same sources, as the draft, in a request of its own.
  3. Block the answer if any claim’s probability of yes is below your threshold.
Python
You can also check every claim in one request: put the claims under keys in the context, and ask one decision per claim that names its key. You pay for the sources once. Decisions in one request can affect each other’s answers, though, so one claim can change the answer for another.

What to watch

  • Drafts marked supported that contain a claim the sources never make.
  • What “supported” means. It means these sources state it, not that the sources are true.
  • Long drafts checked in one go. Split them into claims first.

How well it works

Measured with kettei-core on 651 examples from a public dataset, it chose the right answer 79.0% of the time. Always picking the most common answer scores 53.9%. Your own data will differ, so measure it on examples of yours before you rely on it (improve a decision).
  • Dataset: AttributionBench (Apache-2.0).
  • Sample: 651 rows, 651 measured decisions.
  • Decisions measured: grounded.
  • Wording: tuned.
Always picking the most common answer has an accuracy of 0.5392, and guessing by how common each answer is has a log loss of 0.6901.These are past results on one dataset, not a promise of accuracy on yours.
It was measured one claim at a time, which is how that dataset asks the question.

Next steps