LettuceDetect v2 in Semantic Router: Gen. Hallucination Detection vLLM Endpoint

matt_d1 pts0 comments

LettuceDetect v2 in Semantic Router: Generative Hallucination Detection as a vLLM Endpoint | vLLM Semantic Router

Skip to main content

EnglishEnglish<br>简体中文

LatestLatest<br>v0.3<br>v0.2<br>v0.1

GitHubDashboard

Semantic Router can now verify grounded responses with a generative span detector served by vLLM . The new endpoint detector backend runs LettuceDetect v2 against every fact-checkable answer: unsupported spans are located to the character, typed against a hallucination taxonomy, and explained — in one call, before the response reaches the user.

The models come out of a joint paper between KR Labs and the Semantic Router team, Beyond Document Grounding: Span-Level Hallucination Detection over Code, Tool Output, and Documents (arXiv:2607.00895). This post walks through the paper — the benchmark, the taxonomy, the models, and what they score — and then through the integration that puts the detector into the serving stack.

Why a new detector​

HaluGate established the shape of hallucination mitigation in Semantic Router: a sentinel decides whether a request needs fact-checking, a detector locates unsupported spans in the response, and an explainer classifies why each span is problematic. That architecture works — but its original token-classifier detector is recall-bound (the HaluGate post itself noted that nearly half of hallucinations were missed), and like most detectors it was trained on natural-language document evidence.

Real grounded systems increasingly answer from structured inputs : source code, developer-tool output, markdown, tables. In code and tool output, a single unsupported substring — a wrong field, a fabricated method name, a misreported value — can change program behavior while leaving the rest of the answer correct. A verifier should point to the unsupported substring, not just reject the answer. Prose-trained detectors are weakest exactly there, and as the paper shows, so are large zero-shot LLM judges.

The benchmark: one span-level task across code, tools, and documents​

There was no shared span-level benchmark that treats generated code, tool observations, and structured documents under the same verification task as classic document RAG. The paper builds one: 74,285 newly constructed span-labeled examples across five new sources, plus converted examples from RAGTruth and the 14-language PsiloQA. The full training split contains 145,250 examples, with 6,171 validation and 10,698 test examples, split by grounding source so the test set only uses unseen repositories, papers, and articles.

SourceGroundingBuilt fromCoderepository files, gold fixSWE-bench coding-agent tracesTool outputverbose tool observationsSqueez (query + observation + gold lines)ACLretrieved paper chunksACL-VerbatimREADMEproject documentationpopular GitHub repositoriesWikipediamarkdown articlesopen-wikipedia-markdownRAGTruth / PsiloQAdocumentsincorporated benchmarks<br>The labeling method is what makes exact character offsets possible at this scale. Every example starts from a grounded correct answer ; an injector model (Gemma 4 31B for code, Qwen 3.6 35B for tool output and markdown) proposes a small, localized hallucination as a structured edit, and the exact character span is recovered from the edit itself rather than from a noisy diff. The span stays narrow by construction: in torch.cuda.set_active_device(gpu), only set_active_device is labeled — not the surrounding correct call. The code test split is additionally validated with evidence-based review.

Every span is typed. Three top-level categories carry the "what kind of wrong is this" decision:

Contradiction — wrong logic, values, fields, or conditions in an otherwise plausible answer

Unsupported addition — extra behavior or claims that were neither requested nor evidenced

Fabricated reference — invented methods, attributes, keyword arguments, sections, or identifiers

Thirteen subcategories describe the surface element affected (entity, temporal, numerical, value, relational, identifier, section, attribute, claim, behavior, elaboration, subjective, unspecified), harmonizing the distinctions used by RAGTruth, FAVA, and code-hallucination taxonomies into one scheme that works across prose and code.

The models​

Two detector families are trained on this benchmark, sharing one task formulation and one prompt across all sources:

lettucedect-v2-qwen-2b is a Qwen3.5-2B generative detector fine-tuned to return the hallucinated spans as structured JSON — each quoted verbatim from the answer, typed with category and subcategory, with optional per-span explanations. It is trained and evaluated with a 32,768-token maximum sequence length , so a single prediction can include the user request, repository evidence or retrieved documents, tool output, and the answer to check. Fine-tuning is LoRA (rank 32, α=64) in bf16, learning rate 2×10⁻⁴ with a linear schedule, two epochs at effective batch size 32. Returned strings are matched back into the answer to recover...

span answer code detector hallucination tool

Related Articles