Skip to main content
Every metric class in TrustifAI returns a MetricResult. The structure is identical across all four offline metrics and the confidence metric, so downstream code can process results uniformly regardless of which metric produced them. The .to_dict() method serializes the result to a plain dict suitable for JSON responses, dataframe rows, or logging.

Fields

float
required
Normalized trust score in the range [0.0, 1.0]. Higher values indicate stronger trustworthiness. The meaning of the scale is metric-specific — see the offline metrics reference for per-metric interpretation.
str
required
Human-readable classification of the score, produced by ThresholdEvaluator using thresholds from your config. Common label values include:
  • "Strong Grounding" / "Partial Grounding" / "Likely Hallucinated Answer" — evidence coverage and semantic drift
  • "Stable Consistency" / "Fragile Consistency" / "Unreliable" — epistemic consistency
  • "High Trust" / "Moderate Trust" / "Low Trust" — source diversity
  • "High Confidence" / "Medium Confidence" / "Low Confidence" — confidence
dict
required
Metric-specific breakdown of how the score was derived. Keys vary by metric. All details dicts include an "explanation" string when grading succeeded.
dict | None
default:"None"
Present when the metric incurred external API costs. Omitted from .to_dict() output when None.

.to_dict() method

Serializes the result to a plain Python dict. The score is rounded to 2 decimal places. execution_metadata is included only if it is not None.

Example output

The following shows a MetricResult returned by EvidenceCoverageMetric and its .to_dict() representation:
Use .to_dict() when building JSON API responses or writing results to a database. The rounded score and flat structure make it safe to serialize with json.dumps() without further processing.