When AI models generate responses, sometimes the outputs stray from the original instructions or context, creating fabricated or irrelevant content. This phenomenon is known as hallucination. Hallucinations can be frustrating, especially when the AI’s reliability matters. Whether you’re building a chatbot, summarising documents, or generating answers, identifying hallucinations is key to improving accuracy and trust in your AI system. Hallucinations happen when the output:
  • Doesn’t follow the user’s instructions.
  • Introduces information that isn’t part of the given context.
  • Strays into unrelated topics or makes unsupported claims.
That is why detecting hallucination matters because it ensures accuracy by reducing errors in AI-generated content, which is critical for applications like customer service, research, or education and it can help builds trust with its consistent and grounded responses, thus making users confident in the AI system’s capabilities. Following are the evals to identify hallucinations in AI-generated text content:

1. Prompt/Instruction Adherence

Measures how closely an output follows given prompt instructions, checking for completion of requested tasks and adherence to specified constraints or formats. Click here to read the eval definition of Prompt/Instruction Adherence

a. Using Interface

Inputs Required:
  • Output: The column that has response generated by the AI system.

b. Using SDK

Export your API key and Secret key into your environment variables.
result = evaluator.evaluate(
    eval_templates="prompt_instruction_adherence",
    inputs={
        "output": "Honey doesn’t spoil because its low moisture and high acidity prevent the growth of bacteria and other microbes."
    },
    model_name="turing_flash"
)

print(result.eval_results[0].output)
print(result.eval_results[0].reason)

2. Context Adherence

Evaluates how well responses stay within the provided context by measuring if the output contains any information not present in the given context. Click here to read the eval definition of Context Adherence

a. Using Interface

Inputs Required:
  • Output: The response generated by the AI system.
  • Context: The background information or source material the response should be based on.

b. Using SDK

result = evaluator.evaluate(
    eval_templates="context_adherence",
    inputs={
        "context": "Honey never spoils because it has low moisture content and high acidity, creating an environment that resists bacteria and microorganisms. Archaeologists have even found pots of honey in ancient Egyptian tombs that are still perfectly edible.",
        "output": "Honey doesn’t spoil because its low moisture and high acidity prevent the growth of bacteria and other microbes."
    },
    model_name="turing_flash"
)

print(result.eval_results[0].output)
print(result.eval_results[0].reason)