stated-confidence
Make LLM agents say how sure they are, and what that certainty rests on.
Ask a model to attach a confidence level and an evidential basis to each claim it produces and it fabricates less. The level alone is common practice; the basis is what does the work. Choosing between "documented fact", "expert opinion", and "educated guess" forces a provenance check the model would otherwise skip, and a claim it cannot back gets labelled as a guess or quietly dropped instead of dressed up as a figure.
This package is that schema, the vocabulary behind it, prompt guidance for filling it, and the consistency checks that send hedging-without-meaning-it back to the model. It was extracted from a production knowledge-graph generator where it was observed to sharply reduce invented facts and figures. The effect is observed, not yet measured; an evaluation harness is planned.
Install
pip install stated-confidence # pydantic only
pip install "stated-confidence[pydantic-ai]"
The shape
from stated_confidence import Confidence, DataAnalysisBasis
class Finding(BaseModel):
text: str
confidence: Confidence[DataAnalysisBasis]
A Confidence has:
| field | meaning |
|---|---|
level |
HIGH, MEDIUM, LOW, or SPECULATIVE. Never a number. |
basis |
The kind of evidence, from a basis set chosen for the domain. |
reasoning |
One or two sentences on why that level and basis apply. |
evidence |
What concretely backs the claim: sources, ids, column names, tool results. |
type |
Optional: FACTUAL, CONSENSUS, THEORETICAL, SPECULATIVE. |
label |
Optional localized label for display. |
SPECULATIVE is not the bottom of the scale. It is the level for an idea
the model is offering rather than a claim it is making: an extension a
source suggests, a hypothesis, a what-if. A generator that has somewhere
honest to put an idea does not dress it up as a fact; take that room away
and the ideas come back as fabricated "facts" or disappear altogether.
The level scale is fixed. The basis set is the extension point. Three ship:
GeneralKnowledgeBasisfor claims about the world: documented fact, scientific consensus, historical record, industry standard, expert opinion, theoretical framework, fictional universe, speculation, educated guess.DataAnalysisBasisfor agents reasoning over data they retrieved: query result, computed, schema inference, general knowledge, assumption.DecisionBasisfor recommendations: policy, measured outcome, precedent, trade-off analysis, expert judgment, assumption.
Define your own by subclassing BasisEnum with a __terms__ table and a
__fallback__ value.
Prompting
from stated_confidence import confidence_instructions
system_prompt += confidence_instructions(DataAnalysisBasis, localized=True)
Pydantic AI
from pydantic_ai import Agent
from stated_confidence.pydantic_ai import confidence_output_validator
agent = Agent("openai:gpt-5", output_type=Report)
agent.output_validator(confidence_output_validator())
Every Confidence anywhere in the output is checked. A HIGH level on a
basis of ASSUMPTION, a SPECULATIVE level on a basis of DOCUMENTED_FACT,
or a non-HIGH level with empty reasoning comes back to the model as a
retry listing what to fix. Pass extra (ctx, output) -> list[str] callables for rules that
need run context, such as requiring that evidence names a column the
agent's query actually returned.
Lenient parsing, strict prompting
Models drift. "High" parses. 0.9 parses (as HIGH). An invented basis
value parses as the set's fallback and is logged at WARNING on the
stated_confidence logger so the set can grow from what models actually
say.
TypeScript
The same vocabulary, generated from taxonomy.json, with a Zod schema for
structured output and the same display helpers and consistency checks:
npm install stated-confidence
import { DATA_ANALYSIS_BASIS, confidenceInstructions, checkAll, describe, tone } from 'stated-confidence';
import { confidenceSchema } from 'stated-confidence/zod';
See typescript/README.md. CI checks that the prompt instructions the two packages produce are word-for-word identical.
Display
describe(value) returns a label and description for any level, type, or
basis value; tone(level) maps to positive, neutral, caution, or
warning with no CSS framework attached. taxonomy.json at the package
root is the same vocabulary as data, for other languages to consume.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file stated_confidence-0.1.1.tar.gz.
File metadata
- Download URL: stated_confidence-0.1.1.tar.gz
- Upload date:
- Size: 21.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
887379c9fc308462c7e20f084e2a3fbd0e675ae04947c40914ab8971bed01373
|
|
| MD5 |
da385f1efd4dbeb0703c352214219a9e
|
|
| BLAKE2b-256 |
72513563026b2b08850f86373e473ba14d29653da92ca2c685e7ba7e9878f22b
|
Provenance
The following attestation bundles were made for stated_confidence-0.1.1.tar.gz:
Publisher:
publish.yml on johnwlockwood/stated-confidence
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
stated_confidence-0.1.1.tar.gz -
Subject digest:
887379c9fc308462c7e20f084e2a3fbd0e675ae04947c40914ab8971bed01373 - Sigstore transparency entry: 2747917293
- Sigstore integration time:
-
Permalink:
johnwlockwood/stated-confidence@c796dd0962417ee52919c88ed2701d44e1133485 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/johnwlockwood
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c796dd0962417ee52919c88ed2701d44e1133485 -
Trigger Event:
push
-
Statement type:
File details
Details for the file stated_confidence-0.1.1-py3-none-any.whl.
File metadata
- Download URL: stated_confidence-0.1.1-py3-none-any.whl
- Upload date:
- Size: 17.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7625eaf8cbae88dfd4dac4c4331d54c5ef9e6d8f368832f8fb42f49ffc69769d
|
|
| MD5 |
3c857264d90c7d67654b01d24aad0e80
|
|
| BLAKE2b-256 |
558eed2d14cb56eb39de03ad6d9cd3f3e117fb092b01bb2a200351bb22667fd1
|
Provenance
The following attestation bundles were made for stated_confidence-0.1.1-py3-none-any.whl:
Publisher:
publish.yml on johnwlockwood/stated-confidence
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
stated_confidence-0.1.1-py3-none-any.whl -
Subject digest:
7625eaf8cbae88dfd4dac4c4331d54c5ef9e6d8f368832f8fb42f49ffc69769d - Sigstore transparency entry: 2747917316
- Sigstore integration time:
-
Permalink:
johnwlockwood/stated-confidence@c796dd0962417ee52919c88ed2701d44e1133485 -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/johnwlockwood
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c796dd0962417ee52919c88ed2701d44e1133485 -
Trigger Event:
push
-
Statement type: