UNPKG

llmverify

Version:

AI Output Verification Toolkit — Local-first LLM safety, hallucination detection, PII redaction, prompt injection defense, and runtime monitoring. Zero telemetry. OWASP LLM Top 10 aligned.

55 lines (54 loc) 2.01 kB
/** * Hallucination Risk Heuristic Module * * Detects potential hallucination signals in LLM output. * Uses heuristics - not definitive hallucination detection. * * LIMITATIONS: * - Heuristic-based, not ground-truth verification * - May produce false positives/negatives * - Cannot detect factually incorrect but plausible statements * - Requires prompt context for best results * * @module engines/classification/hallucination * @author Haiec * @license MIT */ import { HallucinationSignals, HallucinationLabel } from './types'; /** * Calculates hallucination risk signals. * * @param prompt - The original prompt * @param output - The LLM output * @param normalizedJson - Parsed JSON if available * @param customHooks - Optional custom detection hooks * @returns Hallucination signals and scores */ export declare function calculateHallucinationSignals(prompt: string, output: string, normalizedJson: unknown | undefined, customHooks?: Array<(prompt: string, output: string) => number>): HallucinationSignals; /** Default weights for hallucination signals (tuned to reduce false positives) */ export declare const DEFAULT_HALLUCINATION_WEIGHTS: { speculative: number; fabricated: number; overconfident: number; contradiction: number; }; /** * Calculates overall hallucination risk score. * * @param signals - Hallucination signals * @param prompt - Original prompt * @param output - LLM output * @param customHooks - Optional custom hooks * @param weights - Optional weight overrides * @returns Risk score (0-1) */ export declare function calculateHallucinationRisk(signals: HallucinationSignals, prompt: string, output: string, customHooks?: Array<(prompt: string, output: string) => number>, weights?: { speculative?: number; fabricated?: number; overconfident?: number; contradiction?: number; }): number; /** * Gets hallucination risk label from score. */ export declare function getHallucinationLabel(risk: number): HallucinationLabel;