Exception: Agentic::Errors::LlmRefusalError

Inherits:
LlmError
  • Object
show all
Defined in:
lib/agentic/errors/llm_error.rb

Overview

Error raised when the LLM refuses to respond

Instance Attribute Summary collapse

Attributes inherited from LlmError

#context, #response

Instance Method Summary collapse

Constructor Details

#initialize(refusal_message, refusal_category: nil, response: nil, context: nil) ⇒ LlmRefusalError

Returns a new instance of LlmRefusalError.

Parameters:

  • refusal_message (String)

    The refusal message from the LLM

  • refusal_category (Symbol, nil) (defaults to: nil)

    The category of refusal

  • response (Hash, nil) (defaults to: nil)

    The raw response from the LLM API

  • context (Hash, nil) (defaults to: nil)

    Additional context about the error



35
36
37
38
39
# File 'lib/agentic/errors/llm_error.rb', line 35

def initialize(refusal_message, refusal_category: nil, response: nil, context: nil)
  super("LLM refused to respond: #{refusal_message}", response: response, context: context)
  @refusal_message = refusal_message
  @refusal_category = refusal_category || determine_refusal_category(refusal_message)
end

Instance Attribute Details

#refusal_categorySymbol (readonly)

Returns The category of refusal.

Returns:

  • (Symbol)

    The category of refusal



29
30
31
# File 'lib/agentic/errors/llm_error.rb', line 29

def refusal_category
  @refusal_category
end

#refusal_messageString (readonly)

Returns The refusal message from the LLM.

Returns:

  • (String)

    The refusal message from the LLM



26
27
28
# File 'lib/agentic/errors/llm_error.rb', line 26

def refusal_message
  @refusal_message
end

Instance Method Details

#retryable_with_modifications?Boolean

Determines whether this refusal is retryable with modifications

Returns:

  • (Boolean)

    True if the refusal can be retried with modifications



43
44
45
# File 'lib/agentic/errors/llm_error.rb', line 43

def retryable_with_modifications?
  [:unclear_instructions, :needs_clarification, :ambiguous_request, :format_error].include?(@refusal_category)
end