Confidence Badge

A small pill under an AI answer that says how much to trust it. A signal meter and label show high, medium or low confidence, and hovering shows the checks behind it.

Preview

Setup

Install with the shadcn CLI

$npx shadcn@latest add https://kinetikui.singhgourav.site/r/confidence-badge.json

One command adds every file, the npm packages and any Kinetik components it builds on. Needs a components.json; the CLI offers to create one if your project has none.

Or install manually

  1. 1

    Run in your terminal:

    $npm install clsx tailwind-merge framer-motion lucide-react
  2. 2

    Copy lib/utils.ts from the Code tab. Skip if you already have cn().

  3. 3

    Copy styles/tokens.css from the Code tab and import it in your global CSS after Tailwind: @import "./styles/tokens.css";

  4. 4

    Create a components/ui/confidence-badge/ folder and copy every file from the Code tab into it. Each file does one job, so you can read or change a piece without the rest.

  5. 5

    Import and render:

    Example
    import { ConfidenceBadge } from "@/components/ui/confidence-badge"
    
    <ConfidenceBadge score={0.86} />

Usage

Pass a score from 0 to 1. The badge picks the level for you:

Example
import { ConfidenceBadge } from "@/components/ui/confidence-badge"

<ConfidenceBadge score={0.86} />
ScoreLevelShows
0.75 and uphighGreen, four bars, “High confidence”
0.45 to 0.75mediumAmber, two bars, “Medium confidence”
Below 0.45lowRed, one bar, “May be inaccurate”
No scorecheckingPulsing bars, “Checking facts…”

While your app is still checking the answer, leave out score. The bars pulse until you pass one.

Show the checks

Pass checks to explain the rating. Hovering or focusing the badge opens a card with the score and each check:

Example
<ConfidenceBadge
  score={0.61}
  checks={[
    { label: "Backed by 2 sources", status: "pass" },
    { label: "Sources disagree on the number", status: "warn" },
    { label: "Answer may be made up", status: "fail" },
  ]}
/>

Use level to set the level yourself, label to change the text (for example “Verified”), and showScore={false} to hide the percentage.

Props

PropTypeDefaultWhat it does
scorenumber—0 to 1. Leave it out while checking.
level"high" | "medium" | "low" | "checking"from scoreSets the level yourself.
labelstringper levelReplaces the badge text.
showScorebooleantrueShow the percentage.
checksConfidenceCheck[]—Each check: { label, status: "pass" | "warn" | "fail" }.

Accessibility

  • Without checks, the badge is a status (role="status"), so screen readers announce changes like “Checking facts…” to “High confidence, 94%”
  • With checks, it's a button that opens the card on hover or keyboard focus. Escape closes it
  • Each check icon has a label: Passed, Warning or Failed
  • Colour is never the only signal: the label and number of bars change too