motleycrew.tools.structured_passthrough

Classes

StructuredPassthroughTool(schema[, name, ...])

A tool that enforces a certain output shape, raising an error if the output is not as expected.

class motleycrew.tools.structured_passthrough.StructuredPassthroughTool(schema: Type[T], name: str = 'structured_passthrough_tool', description: str = 'A tool that checks output validity.', post_process: Callable | None = None, return_direct: bool = True, **kwargs)

Bases: MotleyTool

A tool that enforces a certain output shape, raising an error if the output is not as expected.

__init__(schema: Type[T], name: str = 'structured_passthrough_tool', description: str = 'A tool that checks output validity.', post_process: Callable | None = None, return_direct: bool = True, **kwargs)

Initialize the MotleyTool.

Parameters:
  • name – Name of the tool (required if tool is None).

  • description – Description of the tool (required if tool is None).

  • args_schema – Schema of the tool arguments (required if tool is None).

  • return_direct – If True, the tool’s output will be returned directly to the user.

  • handle_exceptions

    Whether to handle exceptions (return their message as output).

    If True, the tool will return any raised exception’s message as its output.

    If a list of exceptions is provided, only these exceptions will be handled.

    If False, the tool will raise the exception.

    If return_direct is True, the tool will always handle InvalidOutput exceptions, as the tool is considered an output handler.

  • retry_config – Configuration for retry behavior. If None, exceptions will not be retried.

  • tool – Langchain BaseTool to wrap. Usually not needed, as the tool is created from the run method.

run(**kwargs) T

Run the tool with the provided inputs.