Skip to content

Trust summary

The 9-tile traffic-light trust hero assembled from a populated ProfilingResult. See the Evaluation & trust guide.

compute_trust_summary

compute_trust_summary

compute_trust_summary(
    profile: "ProfilingResult",
    *,
    drift_report: "PSIResult | None" = None,
    leakage_report: "LeakageReport | None" = None,
    fairness_report: "FairnessResult | dict[str, FairnessResult] | None" = None,
    fitted: Any | None = None
) -> TrustSummary

Assemble the 9-tile Trust Summary hero.

Pure science layer — no I/O, no caching, no backend specifics. Tiles whose underlying artefact is missing are graded "yellow" with a subtext explaining what's missing, so the Explain hero degrades gracefully on partial profiles.

Parameters:

Name Type Description Default
profile 'ProfilingResult'

The :class:parleml_mli.ProfilingResult to grade. Carries the evaluation, rules, archetypes, error-tree, EDA, and (when explanations were computed) the PSI / fairness artefacts the tiles consume.

required
drift_report 'PSIResult | None'

Optional :class:parleml_mli.explanations.PSIResult. Defaults to profile.explanations_.psi.

None
leakage_report 'LeakageReport | None'

Optional :class:parleml_mli.eda.LeakageReport. Defaults to profile.eda_.leakage_report.

None
fairness_report 'FairnessResult | dict[str, FairnessResult] | None'

Optional :class:parleml_mli.explanations.FairnessResult (single sensitive feature) or dict[str, FairnessResult]. Defaults to profile.explanations_.fairness.

None
fitted Any | None

Reserved for tiles that need the live model (none currently — every tile reads from the persisted profile). Accepted for forward compatibility with the §I3 spec; ignored today.

None

Returns:

Type Description
TrustSummary

Frozen 9-tile container in :data:TRUST_TILE_KEYS order with an overall_grade and a template-based headline.

TrustSummary

TrustSummary dataclass

TrustSummary(
    tiles: list[TrustTile],
    overall_grade: TrustBadge,
    headline: str,
    schema_version: int = TRUST_SCHEMA_VERSION,
)

The 9-tile Trust Summary hero assembled for one experiment.

Attributes:

Name Type Description
tiles list[TrustTile]

Exactly 9 :class:TrustTile entries, in the canonical order defined by :data:TRUST_TILE_KEYS.

overall_grade TrustBadge

Worst-of-tiles grade (green / yellow / red). A single red tile pulls the headline to red; a single yellow tile pulls it to yellow. This matches how analysts read the hero — "anything that's red, I have to defend".

headline str

One-line plain-English narrative summarising the hero. Template-based today (e.g. "Trust score: yellow — 5 green, 3 yellow, 1 red"); future revisions may swap in an LLM narration without changing the schema.

schema_version int

:data:TRUST_SCHEMA_VERSION. Backend keys its ETag off this so a library upgrade invalidates client caches cleanly.

to_dict

to_dict() -> dict[str, Any]

JSON-clean dict suitable for the FastAPI response body.

get

get(key: TrustTileKey) -> TrustTile | None

Return the tile keyed by key, or None if missing.

Convenience for callers that want one specific tile (e.g. the TrustStrip on the Models page only renders model_lift / drift / fairness).

TrustTile

TrustTile dataclass

TrustTile(
    key: TrustTileKey,
    label: str,
    value: float | int | str,
    badge: TrustBadge,
    subtext: str,
    details: dict[str, Any] = dict(),
)

One grading for one Trust Summary surface.

Attributes:

Name Type Description
key TrustTileKey

Stable machine identifier — one of the nine values in :data:TRUST_TILE_KEYS. The frontend keys deep-links and translation strings off this; never change it without bumping :attr:TrustSummary.schema_version.

label str

Human-readable tile title (e.g. "Model lift").

value float | int | str

Headline scalar for the tile. float for skill metrics, int for counts, str for the "n/a" sentinel emitted when the underlying artefact is missing.

badge TrustBadge

Traffic-light grade. Threshold logic lives in :mod:parleml_mli.trust.thresholds.

subtext str

One-line plain-English explanation — what the value means and where to dig deeper. Surfaced under the tile in the hero block and as the tooltip in the compact TrustStrip.

details dict[str, Any]

Optional small dict for extra context that the UI can render on hover (e.g. {"max_feature": "transaction_amount"} on the drift tile). Never required; consumers tolerate {}.

to_dict

to_dict() -> dict[str, Any]

JSON-clean dict suitable for the FastAPI response body.

Tile keys & thresholds

The canonical tile ordering and the traffic-light grading bands (both re-exported from the top level).

TRUST_TILE_KEYS module-attribute

TRUST_TILE_KEYS: tuple[TrustTileKey, ...] = (
    "model_lift",
    "calibration",
    "drift",
    "fairness",
    "error_pocket",
    "rules_hold_up",
    "archetype_coverage",
    "leakage_findings",
    "stability",
)

Canonical ordering of the 9 tiles — matches the UI layout in ui_concept.md §12.1. :func:parleml_mli.trust.compute_trust_summary guarantees the returned tiles list is in this order so consumers can index by position when convenient.

TRUST_THRESHOLDS module-attribute

TRUST_THRESHOLDS: dict[str, TrustThresholdBand] = {
    "model_lift": {
        "green": 1.5,
        "yellow": 1.1,
        "direction": "higher",
    },
    "calibration": {
        "green": 0.05,
        "yellow": 0.1,
        "direction": "lower",
    },
    "drift": {
        "green": 0.1,
        "yellow": 0.25,
        "direction": "lower",
    },
    "fairness": {
        "green": 0.0,
        "yellow": 2.0,
        "direction": "count",
    },
    "error_pocket": {
        "green": 0.0,
        "yellow": 2.0,
        "direction": "count",
    },
    "rules_hold_up": {
        "green": 0.6,
        "yellow": 0.3,
        "direction": "higher",
    },
    "archetype_coverage": {
        "green": 0.85,
        "yellow": 0.6,
        "direction": "higher",
    },
    "stability": {
        "green": 0.7,
        "yellow": 0.4,
        "direction": "higher",
    },
}

Per-tile numeric colour bands. leakage_findings is not present because that tile uses :data:LEAKAGE_SEVERITY_GATE instead.