input_schema: Defines what parameters a tool accepts. Wrap it inToolRequestBody.model_validate()output_schema: Defines what data a tool returns. Wrap it inToolResponseBody.model_validate()
tool, ToolRequestBody, and ToolResponseBody from the ADK package:
Python
- Runtime validation: Ensures data conforms to expected types and constraints
- UI generation: Automatically creates forms in the WatsonX Orchestrate interface
- Documentation: Provides clear parameter descriptions for you and LLMs
- API integration: Uses in REST APIs for programmatic tool management
Configuring input schemas
Input schemas define the parameters your tool accepts, serving as the contract between your tool and its callers. They specify what data you require, what is optional, and the expected format for each parameter. Input schemas provide validation, automatic UI form generation, clear documentation, type safety, and guidance for AI agents on proper tool usage. Define schemas with clear parameter descriptions, appropriate types, minimal required fields, numeric constraints where applicable, and focused functionality. You can configure input schemas in two primary forms: single required parameter for simple tools, or multiple parameters with a mix of required and optional fields for more complex operations.Configuring single parameter
This form of input schema has one required parameter. Use this pattern when your tool needs exactly one piece of information to function.Python
Configuring multiple parameters
When your tool needs multiple pieces of information, define a mix of required and optional parameters. This pattern is common for update operations where you must provide some fields while others remain optional.- Required parameters: List them in the
requiredarray - Optional parameters: Do not include them in the
requiredarray. Use| None(Python 3.10+) orOptional[T]fromtypingin the function signature - Default values: Give optional parameters
= Noneas default value
Python
Configuring output schemas
Output schemas define the structure of data your tool returns, serving as the contract between your tool and its consumers. They specify the format and type of data that callers can expect to receive. Output schemas provide validation, automatic UI display generation, clear documentation, type safety, and proper data flow between tools and agents. Define schemas with clear descriptions, appropriate types, and structures that match your return values exactly. You can configure output schemas in two primary forms: simple string returns for unstructured or formatted text, or Pydantic models for structured data with multiple fields.Returning simple parameters
Use simple string returns for tools that return unstructured text or single values. This is the most common pattern for tools that format their output as human-readable text.Python
Python
Returning multiple parameters
When your tool returns structured data with multiple fields of different types, use Pydantic models as return types. For more information, see Pydantic models.Configuring dynamic schemas
In integration-heavy environments, schemas change frequently. Dynamic input and output schemas enable select fields in a tool’s input to be mutable at runtime—securely and predictably—without affecting immutable core fields. Use dynamic schemas when:- You need to add new attributes to objects such as CRM records
- You need a small number of user-defined fields beyond a stable core API
- You want Builder UI users to change types for dynamic fields only. For example, change string to number
Python
Python
Parameter types
JSON Schema supports various data types for defining tool parameters. Each type has specific properties and validation rules that help ensure data integrity and provide clear documentation.String
Use thestring type for text-based parameters such as names, descriptions, identifiers, or any free-form text input.
Python
Integer
Use theinteger type for whole numbers without decimal points. This is ideal for counts, indices, IDs, or any numeric value that should not have fractional parts.
Python
Python
Number (Float)
Use thenumber type for numeric values that may include decimal points. This type accepts both integers and floating-point numbers.
Python
Python
Boolean
Use theboolean type for true or false values.
Python
Date
Use thestring type with format: "date" for date values. Dates must be in ISO 8601 format: YYYY-MM-DD.
Python
"2024-01-15", "2023-12-31", "2025-06-01"
Nested object
Use theobject type for complex parameters that contain multiple related fields. This allows you to group related data together in a structured way.
Python
- Always include a
descriptionfor the object and each nested field - Use the
requiredarray to specify which nested fields are mandatory - Keep nesting levels reasonable and avoid deeply nested structures when possible
- Consider using Pydantic models for complex nested structures. For more information, see Pydantic models
Pydantic models
When you have complex nested structures or want type-safe parameter definitions, you can define Pydantic models and use them as both input parameters and return types. Benefits of Pydantic models:- Type validation: Automatic validation of data structure
- Clear contracts: Explicit definition of what the tool accepts and returns
- IDE support: Autocomplete and type hints when working with parameters and results
- Reusability: Use models across multiple tools
- Documentation: Self-documenting parameters and return values
Using as input parameters
First, create your Pydantic model classes with clear docstrings and type hints:Python
Python
Using as return parameter
When your tool returns structured data with multiple fields of different types, define a Pydantic model as the return type. This provides type safety and clear structure for complex return values. Define the Pydantic model:Python
Python
Python
AgentRun context
When your tools need access to user identity, credentials, or context variables, use theAgentRun parameter. This parameter is special and you should NOT include it in the input schema.
The framework automatically injects the
AgentRun context parameter. Do not define it in your input schema. Only include it in your function signature.Python
Important rules
- Every parameter must have a description - You need this for the parameter to show up in the WatsonX UI
- Parameter names must match - Match schema property names exactly to function parameter names
-
List only required parameters - Only include parameters in the
requiredarray that you truly require -
Optional parameters - Mark optional parameters with
| None(Python 3.10+) orOptional[T]fromtypingin the function signature, and set their default value to= None - Output schema must match return type - Match the output schema exactly to the Pydantic model structure or return type
-
Context parameter is special - The framework injects the
context: AgentRunparameter and you should NOT include it in the input schema. For more information, see AgentRun context -
Function signature must match schema - Match the function parameters to the input schema properties exactly:
Python
See also
- Tool response structure and annotations - Learn about returning structured responses with widgets
- Widget integration - Add interactive forms to your tool responses
- Creating tools - General guide to creating Python tools

