karenina.benchmark.verification.evaluators.trace.abstention¶
abstention
¶
Abstention detection for identifying when models refuse to answer questions.
Classes¶
AbstentionResult
¶
Bases: BaseModel
Result of abstention detection by LLM judge.
Source code in src/karenina/benchmark/verification/evaluators/trace/abstention.py
Functions¶
detect_abstention
¶
detect_abstention(
raw_llm_response: str,
parsing_model: ModelConfig,
question_text: str,
prompt_config: PromptConfig | None = None,
) -> tuple[bool, bool, str | None, dict[str, Any]]
Detect if the model refused to answer or abstained from answering.
This function uses an LLM to analyze the response and determine if it contains patterns indicating refusal, abstention, or evasion. The adapter handles retries for transient errors internally via RetryExecutor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str
|
The raw response text from the answering model |
required |
|
ModelConfig
|
Configuration for the model to use for abstention detection |
required |
|
str
|
The original question that was asked |
required |
Returns:
| Type | Description |
|---|---|
bool
|
Tuple of (abstention_detected, check_performed, reasoning, usage_metadata): |
bool
|
|
str | None
|
|
dict[str, Any]
|
|
tuple[bool, bool, str | None, dict[str, Any]]
|
|
Examples:
>>> config = ModelConfig(id="parser", model_provider="openai", ...)
>>> detected, performed, reasoning, metadata = detect_abstention("I cannot answer this", config, "What is X?")
>>> print(detected, performed, reasoning)
True, True, "Response contains explicit refusal pattern"