Skip to main content

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:

  • GeneralKnowledgeBasis for claims about the world: documented fact, scientific consensus, historical record, industry standard, expert opinion, theoretical framework, fictional universe, speculation, educated guess.
  • DataAnalysisBasis for agents reasoning over data they retrieved: query result, computed, schema inference, general knowledge, assumption.
  • DecisionBasis for 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.

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

stated_confidence-0.1.0.tar.gz (17.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

stated_confidence-0.1.0-py3-none-any.whl (16.9 kB view details)

Uploaded Python 3

File details

Details for the file stated_confidence-0.1.0.tar.gz.

File metadata

  • Download URL: stated_confidence-0.1.0.tar.gz
  • Upload date:
  • Size: 17.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for stated_confidence-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c1040db6ca5d9daa3b7893ea6e6a15787b674d22b8a6cb32151710b5022aa652
MD5 d817373cdff911073c92452bae63e99d
BLAKE2b-256 2c55219bcf4dbcb79ea140cff6c448059832ce1018396475fc76aad4d9c00c62

See more details on using hashes here.

Provenance

The following attestation bundles were made for stated_confidence-0.1.0.tar.gz:

Publisher: publish.yml on johnwlockwood/stated-confidence

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file stated_confidence-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for stated_confidence-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 9af8ba9e03789fa0ba6b451b07becae4b424c005059faa283ba89226745a2d22
MD5 73fdedb260eb3529f90a48c06b031e5b
BLAKE2b-256 dafc9dc075773f967807159dbd203576ecf010705d2f90dea3183507a4bce0a4

See more details on using hashes here.

Provenance

The following attestation bundles were made for stated_confidence-0.1.0-py3-none-any.whl:

Publisher: publish.yml on johnwlockwood/stated-confidence

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.1.2

2 files

0.1.1

2 files

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page