Skip to main content

Groundedness

The Groundedness metric measures whether a model’s generated response remains faithful to the input context and avoids hallucinations or speculative reasoning. It helps evaluate factual consistency and traceability, especially when LLMs generate answers based on external sources, retrieved passages, or structured data.

This metric is critical in RAG (retrieval-augmented generation), enterprise QA systems, and any use case where factuality is a core requirement.

When to Use

Apply the Groundedness metric when a model is expected to remain tightly aligned with an authoritative context, such as:

  • Knowledge-grounded agents that cite documents or structured data
  • Enterprise chat assistants referencing product, support, or policy content
  • Tool-using agents interpreting intermediate function/state output
  • Factual creative assistants (e.g., educational, journalistic, research support)

Score

The API returns a score (float, 0.0 – 1.0) under the groundedness key.

  • 1.0: Fully faithful to the context; no unsupported or fabricated claims.
  • 0.7–0.99: Mostly accurate with minor factual ambiguity.
  • 0.2–0.7: Some inaccuracies or invented facts present.
  • 0.0–0.2: Severe hallucinations or clear contradiction with context.

A higher score is better. A lower score indicates factual inconsistency, hallucinations, or unsupported reasoning.

API Request & Response Example

[
{
"context": "The Eiffel Tower is located in Paris, France.",
"generated_text": "The Eiffel Tower is located in England.",
"config": {
"groundedness": {
"detector_name": "default",
"explain":true
}
}
}
]

Code Examples

# Synchronous example

import os
from aimon import Client
import json

# Initialize client
client = Client(auth_header=f"Bearer {os.environ['AIMON_API_KEY']}")

# Construct payload
payload = [{
"generated_text": "The Eiffel Tower is in Berlin.",
"context": ["The Eiffel Tower is located in Paris, France."],
"config": {
"groundedness": {
"detector_name": "default",
"explain": True
}
},
"publish": False
}]

# Call sync detect
response = client.inference.detect(body=payload)

# Print result
print(json.dumps(response[0].groundedness, indent=2))