Skip to content

Annotations.Schema does not support nullable parameter to mark optional function parameters #493

@Lezeper

Description

@Lezeper

** Please make sure you read the contribution guide and file the issues in the rigth place. **
Contribution guide.

Describe the bug
Google ADK's @Annotations.Schema annotation does not provide a way to mark parameters as
optional/nullable. When using FunctionTool.create(), all method parameters are included in the "required"
array of the generated function schema, with no mechanism to specify that certain parameters are optional.

This causes issues when integrating with LLM providers (like AWS Bedrock) that need to differentiate
between required and optional parameters in function calling schemas.

To Reproduce
Steps to reproduce the behavior:

  1. Create a tool service with a method that has optional parameters:
  @Service
  public class ExampleToolService {
      @Annotations.Schema(name = "exampleTool", description = "Example tool with optional parameters")
      public Map<String, Object> executeExample(
              @Annotations.Schema(name = "requiredParam", description = "A required parameter") String 
  requiredParam,
              @Annotations.Schema(name = "optionalParam", description = "An optional parameter with 
  default") Integer optionalParam) {
          // implementation
      }
  }
  1. Create a FunctionTool using FunctionTool.create():
    FunctionTool tool = FunctionTool.create(exampleToolService, "executeExample");
  2. Inspect the generated function schema
  3. Observe that both parameters appear in the "required" array with no way to mark optionalParam as
    optional

Expected behavior
The @Annotations.Schema annotation should support a nullable parameter (e.g., nullable = true) to indicate
that a parameter is optional:

@Annotations.Schema(name = "optionalParam", description = "An optional parameter", nullable = true)
Integer optionalParam

This should generate a schema where optional parameters are excluded from the "required" array:

{
"required": ["requiredParam"]
}

Instead of the current behavior where all parameters are required:

{
"required": ["requiredParam", "optionalParam"]
}

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: macOS
  • Java version: 17
  • ADK version: 0.3.0

Additional context
The current workaround requires developers to use reflection to check for third-party nullable annotations
(like javax.annotation.Nullable) and manually rebuild the "required" array when constructing the schema
for LLM providers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions