llumpy.retry.RetryHandler

class RetryHandler[source]

Bases: _FormatMixIn, ABC

Retry handler to validate LLM responses

__init__()

Methods

__init__()

try_prompt(prompt_fn, extract_fn, retries)

Prompt an LLM to get a valid response

try_prompt(prompt_fn, extract_fn, retries)[source]

Prompt an LLM to get a valid response

Parameters:
  • prompt_fn (Callable[[], Any]) – Prompt callback function

  • extract_fn (Callable[[Any], str | None]) – Prompt text extraction callback function

  • retries (int) – Number of retries allowed

Raises:

ExceededRetriesError – Exceed the number of permitted retries

Returns:

Validated chat response text

Return type:

Any