googleapis / googleapis/python-genai

`const` keyword is not supported in function definitions

Open
#1,093 8 comments 0 reactions 1 assignee Claimed by @Venkaiahbabuneelam View on GitHub
priority: p2 type: feature request
Dominant language
Python
Stars
4k
Forks
1k
Avg merge
2d 11h
Merged PRs (30d)
40

Description

The `const` JSONSchema keyword is not supported in function definitions. The `const` keyword is very useful for type discriminations. To repro the issue, do the following
```
import google.genai as genai

tool_definition = {
"name": "get_weather",
"description": "Get the weather",
"parameters": {
"properties": {
"type": {"description": "the type", "type": "string", "const": "city"},
"value": {
"description": "The value to get the weather for",
"type": "string",
},
},
"required": ["type", "value"],
"type": "object",
},
}

client = genai.Client()
response = client.models.generate_content(
model="gemini-2.5-flash",
contents=[
{
"role": "user",
"parts": [{"text": "whats the weather in the city of Tokyo?"}],
}
],
config={"tools": [{"function_declarations": [tool_definition]}]},
)
```
this will produce this error
```
ValidationError: 5 validation errors for GenerateContentConfig
tools.0.Tool.function_declarations.0.parameters.properties.type.const
Extra inputs are not permitted [type=extra_forbidden, input_value='city', input_type=str]
For further information visit https://errors.pydantic.dev/2.11/v/extra_forbidden
tools.0.callable
Input should be callable [type=callable_type, input_value={'function_declarations':...'], 'type': 'object'}}]}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.11/v/callable_type
tools.0.Tool.name
Field required [type=missing, input_value={'function_declarations':...'], 'type': 'object'}}]}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.11/v/missing
tools.0.Tool.inputSchema
Field required [type=missing, input_value={'function_declarations':...'], 'type': 'object'}}]}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.11/v/missing
tools.0.is-instance[ClientSession]
Input should be an instance of ClientSession [type=is_instance_of, input_value={'function_declarations':...'], 'type': 'object'}}]}, input_type=dict]
For further information visit https://errors.pydantic.dev/2.11/v/is_instance_of
```

I know that this can addressed with an enum workaround
```
{"description": "the type", "type": "string", "enum": ["city"]}
```

but I prefer not because it increases token count. Plus, all other major AI providers (openai, anthropic, etc.) support `const` in function definitions

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.