LLMAssert
Matchers

toBeGroundedIn

Assert that a response is factually grounded in provided context

Catches hallucinations by checking every claim in the response against the provided context. Score 1.0 means fully grounded; 0.0 means fabricated.

Usage

await expect(response).toBeGroundedIn(context);
await expect(response).toBeGroundedIn(context, { threshold: 0.9 });

Negation

Verify a response adds information beyond the context:

await expect(creativeResponse).not.toBeGroundedIn(context);

Example — FAQ chatbot

import { test, expect } from "@llmassert/playwright";

test("chatbot answers are grounded in FAQ", async () => {
  const question = "Do you offer free shipping?";
  const response = await chatbot.ask(question);
  const faqDocs = await loadFAQ();

  await expect(response).toBeGroundedIn(faqDocs);
});

Threshold guidance

ThresholdMeaningUse when
0.95Strict — reject minor paraphrasingRegulated content, legal docs, medical advice
0.85Tight — accept rearrangement, reject additionsCustomer-facing FAQ bots
0.70Default — allows reasonable inferenceGeneral chatbots, internal tools
0.50Permissive — accepts loose connectionsCreative writing, brainstorming assistants

The judge checks every factual claim against the source context. A response that invents a single detail not in the context will score lower, even if the rest is accurate.

Dashboard type

Appears as assertion type groundedness in the dashboard.

On this page