Expand description
Detect and truncate hallucinated conversation turns in LLM responses.
During extended conversations (30+ messages), LLMs can start predicting both
sides of dialogue — generating fake [User]: turns within their own responses
and then answering them. This crate detects those markers and truncates the
response at the first hallucinated turn boundary.
Also detects action hallucinations — when a model claims to have performed actions (file writes, command execution) without corresponding tool calls.
§Usage
use response_validator::{validate_text, detect_action_claims};
// Detect hallucinated turn markers
let result = validate_text("Here is my analysis.\n[User]: fake question");
assert!(result.was_truncated);
assert_eq!(result.text, "Here is my analysis.");
// Detect action claims
let claims = detect_action_claims("I've updated MEMORY.md with the notes.");
assert_eq!(claims.len(), 1);Structs§
- Action
Claim - A detected action claim in response text.
- Action
Claim Validation - Result of validating action claims against actual tool usage.
- Validation
Result - Result of validating a response for hallucinated turn markers.
Enums§
- Action
Category - Category of action an LLM claims to have performed.
- Content
Block - A content block from an LLM response.
Functions§
- detect_
action_ claims - Detect action claims in a text string.
- validate_
action_ claims - Validate action claims in a response against actual tool usage.
- validate_
content_ blocks - Validate content blocks from an LLM response.
- validate_
text - Validate a text response for hallucinated turn markers.