Tool Decorator
Auto-instrumentation for function calls
Auto-instrumentation for function calls
The Tool decorator helps you define Tools for use in function calling. It automatically instruments function calls and creates Tool Logs on Humanloop.
Calling a decorated function will create a Tool Log with the following fields:
inputs: The function arguments.output: The function return value.error: The error message if the function call fails.The decorated function will have the same signature as the original function and will have a json_schema attribute containing the inferred JSON Schema.
Decorating a function will set a json_schema attribute that can be used for function calling.
In Python, the decorator automatically infers a JSON Schema from the source code, argument signature, and docstrings:
Optional[T] or T | None) are marked as not requiredSupported type hints:
Each function call creates a Tool Log with the following fields:
error field.None when an error occurs.HumanloopRuntimeError is not caught and will be re-raised, as it indicates incorrect SDK or decorator usage.json_schema attribute when passing the tool to prompts.call()For a deeper understanding of Tools and their role in the Humanloop platform, refer to our Tools documentation.
For attaching a Tool to a Prompt, see Tool calling in Editor and linking a Tool to a Prompt.