Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/TangibleResearch/Halgorithem/llms.txt

Use this file to discover all available pages before exploring further.

Halgorithem is designed to slot into AI agent pipelines as a post-generation verification step. After an LLM generates a response, Halgorithem checks each claim against your source documents for hallucinations before the output is used downstream. The key entry point is Engine.verify() — it takes already-loaded source documents and an AI-generated string, and returns a structured list of claims with statuses.

How Engine.verify() works

Engine.verify() does not make any LLM calls. It only runs the local sentence-transformer model to compare claims against your source documents. This means it is fast, deterministic, and does not incur API costs during verification.
The method signature is:
eng.verify(ai_output, source_docs, threshold=0.30)
It returns a dict with two keys:
  • claims — list of claim dicts, each with status, claim, score, chunk_text, and unsupported_terms
  • summary — a human-readable string like "8/10 supported, 1/10 weak, 0/10 contradictions, 1/10 hallucinations"

Generic integration pattern

Use this pattern to add hallucination checking to any pipeline that has already generated an AI response:
from engine import Engine

eng = Engine()

# After your pipeline generates a response:
source_docs = eng.load_truth_files(["knowledge_base.txt"])
verification = eng.verify(ai_output=llm_response, source_docs=source_docs, threshold=0.30)

if any(c["status"] == "HALLUCINATION" for c in verification["claims"]):
    # Handle hallucination
    print("Hallucinations detected:", verification["summary"])
load_truth_files() returns the same list-of-dicts format as scrape_urls(), so you can mix file and URL sources by combining both calls.

Framework-specific patterns

Add a verification node to your graph that runs after the generation step. The node reads from state["ai_response"] and writes the verification result back into state:
from engine import Engine

eng = Engine()

def verify_node(state):
    """LangGraph node: verifies AI output for hallucinations."""
    source_docs = eng.load_truth_files(state["source_files"])
    result = eng.verify(
        ai_output=state["ai_response"],
        source_docs=source_docs,
        threshold=0.30
    )
    return {**state, "verification": result, "has_hallucinations": any(
        c["status"] == "HALLUCINATION" for c in result["claims"]
    )}
Wire it into your graph after the LLM generation node. You can then route on state["has_hallucinations"] to retry, flag, or reject the response.

Build docs developers (and LLMs) love