Skip to main content
Define schemas for watsonX Orchestrate Python tools. A tool schema defines the structure of data that flows into and out of your Python tools. It consists of two parts:
  • input_schema: Defines what parameters a tool accepts. Wrap it in ToolRequestBody.model_validate()
  • output_schema: Defines what data a tool returns. Wrap it in ToolResponseBody.model_validate()
Import tool, ToolRequestBody, and ToolResponseBody from the ADK package:
Python
Schemas serve multiple purposes:
  • 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 required array
  • Optional parameters: Do not include them in the required array. Use | None (Python 3.10+) or Optional[T] from typing in the function signature
  • Default values: Give optional parameters = None as 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
Function signature:
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 the string type for text-based parameters such as names, descriptions, identifiers, or any free-form text input.
Python

Integer

Use the integer 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
You can add validation constraints to ensure values fall within acceptable ranges:
Python

Number (Float)

Use the number type for numeric values that may include decimal points. This type accepts both integers and floating-point numbers.
Python
You can add validation constraints to ensure values fall within acceptable ranges:
Python

Boolean

Use the boolean type for true or false values.
Python

Date

Use the string type with format: "date" for date values. Dates must be in ISO 8601 format: YYYY-MM-DD.
Python
Example values: "2024-01-15", "2023-12-31", "2025-06-01"

Nested object

Use the object type for complex parameters that contain multiple related fields. This allows you to group related data together in a structured way.
Python
Best practices:
  • Always include a description for the object and each nested field
  • Use the required array 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
Then, use your Pydantic models in the input schema. Each field in the model must be represented in the schema properties:
Python
Important:
  • Use descriptive class names that clearly indicate the data structure
  • Add docstrings to explain what the model represents
  • Define all fields with appropriate type hints
  • Use optional fields with | None or Optional[T] for non-required parameters
  • Match the schema properties to the Pydantic model fields exactly
  • Include required fields in the model in the schema’s required array
  • Ensure each nested object in the schema corresponds to a Pydantic model

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
Use in output schema: Match the output schema exactly to your Pydantic model’s structure:
Python
Complete example with complex return types: This example shows a tool that returns a complex structure with arrays and nested objects:
Python

AgentRun context

When your tools need access to user identity, credentials, or context variables, use the AgentRun 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

  1. Every parameter must have a description - You need this for the parameter to show up in the WatsonX UI
  2. Parameter names must match - Match schema property names exactly to function parameter names
  3. List only required parameters - Only include parameters in the required array that you truly require
  4. Optional parameters - Mark optional parameters with | None (Python 3.10+) or Optional[T] from typing in the function signature, and set their default value to = None
  5. Output schema must match return type - Match the output schema exactly to the Pydantic model structure or return type
  6. Context parameter is special - The framework injects the context: AgentRun parameter and you should NOT include it in the input schema. For more information, see AgentRun context
  7. Function signature must match schema - Match the function parameters to the input schema properties exactly:
    Python

See also