Is Every Sentence Backed by Sources? Enforcing Groundedness in RAG
Your model wrote a fluent four-paragraph response, but slipped in a plausible fiction not found anywhere in your knowledge base. Here is how to verify sentence-by-sentence attribution.
The Reality Check
LLMs naturally smooth over narrative gaps using prior world knowledge. If 9 out of 10 sentences come from your docs but the 10th is an invented promise, your business is on the hook. Groundedness proves every assertion has an anchor.
The Menace of 'Plausible Infiltration'
Foundation models write with persuasive confidence. When summarizing complex enterprise, medical, or financial documents, models regularly inject assumptions, outdated training memories, or stylistic embellishments that were never in the source context.
Real-World Scenario
"A SaaS support bot retrieves documentation stating: 'Users can export up to 10,000 rows to CSV.' The LLM outputs: 'You can export up to 10,000 rows to CSV or trigger an automatic recurring webhook.' Webhook exports do not exist in the product. An enterprise customer builds an automation around the phantom feature and cancels their contract when it fails."
The Hidden Costs of Leaving This Unchecked:
- Engineering hours wasted investigating bug reports for non-existent product features promised by LLMs.
- Legal exposure when generated advice contradicts contractual service level agreements (SLAs).
- Rapid erosion of customer trust when human users detect unverified claims in official assistant answers.
Sentence-Level Evidence Tracing
Groundedness inspects the generated output and verifies that each factual assertion traces directly back to supporting evidence in the retrieved context passages.
Prevented
Extraneous training data contaminating domain-specific answers.
Prevented
Unattributed marketing exaggerations or fabricated capabilities.
Prevented
Subtle numerical drift (e.g., transforming 'within 5 business days' into 'within 24 hours').
Real-Time Egress Safety Gate
Before streaming or displaying generated text to the user, pass both retrieved context and model output through LayaEval's Groundedness check. If the score drops below 3.0/5.0, quarantine the response and request regeneration with zero temperature or source-only prompt constraints.
04 · Value Proposition
Why High-Velocity Teams Use LayaEval
Advantage 01
Sub-10ms Runtime
Runs locally in pure Python. No waiting 3 seconds for an external LLM judge.
Advantage 02
Deterministic Attribution
Clear normalized scoring from 0.0 to 5.0 with explainable pass/fail thresholds you can test in CI.
Advantage 03
Zero Token Surcharge
Audit 100% of generated responses without doubling your monthly model inference expenses.
Run This Check in 4 Lines of Python
In just a few lines of Python, your pipeline intercepts the unsupported claim regarding free on-site engineering consultations before it ever reaches a prospective client.
1from layaeval import Groundedness2
3# Initialize Groundedness check (pass threshold: 3.0 / 5.0)4evaluator = Groundedness(threshold=3.0)5
6context = (7 "Enterprise plans include 24/7 dedicated telephone support and a 99.99% uptime SLA. "8 "Standard plans include business-hours email support with a 24-hour turnaround target."9)10
11# Response contains one accurate clause and one ungrounded claim12response = (13 "Enterprise plans feature 24/7 phone support and a 99.99% uptime SLA. "14 "We also offer unlimited free on-site engineering consultations."15)16
17result = evaluator(retrieved_context=context, response=response)18
19print(f"Passed: {result.passed}") # False20print(f"Score: {result.value:.1f}/5.0") # e.g. 2.521print(f"Confidence: {result.confidence}") # e.g. 0.9422
23if not result.passed:24 # Reject output or trigger re-generation with strict grounding25 print("Alert: Generated response contains ungrounded claims!")API Payload & Evaluation Response
Audit response grounding via API in your service mesh before releasing responses to clients:
Request (cURL / POST)
1curl -X POST https://api.yourdomain.com/v1/eval/groundedness \2 -H "Content-Type: application/json" \3 -d '{4 "retrieved_context": "Enterprise plans include 24/7 dedicated telephone support...",5 "response": "Enterprise plans feature 24/7 phone support and unlimited free on-site consultations."6 }'Instant Sub-10ms JSON Response
1{2 "metric": "Groundedness",3 "passed": false,4 "score": 2.5,5 "threshold": 3.0,6 "confidence": 0.94,7 "latency_ms": 6.88}- 1Insert Groundedness in your API egress path before delivering responses to end users.
- 2Set an initial threshold of 3.0 and test against golden evaluation datasets.
- 3Log failing responses to identify prompts prone to hallucination.
Interactive Playground
Test Groundedness in our visual demo
Tweak query and context sliders to see live pass/fail scoring in real time.
Continue Reading