Skip to main content

Crate response_validator

Crate response_validator 

Source
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§

ActionClaim
A detected action claim in response text.
ActionClaimValidation
Result of validating action claims against actual tool usage.
ValidationResult
Result of validating a response for hallucinated turn markers.

Enums§

ActionCategory
Category of action an LLM claims to have performed.
ContentBlock
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.