motleycrew.utils.structured_output_with_retries

Functions

structured_output_with_retries(schema, ...)

Use MotleyCrew agent with retries to extract structured output.

motleycrew.utils.structured_output_with_retries.structured_output_with_retries(schema: ~typing.Type[~motleycrew.utils.structured_output_with_retries.T], prompt: str, input_messages: ~typing.List[~langchain_core.messages.human.HumanMessage] | dict, language_model: ~langchain_core.language_models.base.BaseLanguageModel | None = None, post_process: ~typing.Callable[[~pydantic.main.BaseModel], ~pydantic.main.BaseModel] = <function <lambda>>, handle_exceptions: bool | list[~typing.Type[Exception]] = True) T

Use MotleyCrew agent with retries to extract structured output.

Parameters:
  • schema – The Pydantic model to extract

  • prompt – Instructions

  • input_messages – List of messages containing the image and text

  • language_model – The language model to use

  • post_process – Optional function to post-process the output, for example for validation

  • handle_exceptions – Whether to handle exceptions (True/False) or a list of specific exception types to handle

Returns:

An instance of the schema with extracted data