Implementation:Cohere ai Cohere python ToolV2Function Model
| Knowledge Sources | |
|---|---|
| Domains | SDK, Tool Use, Function Calling, Pydantic Models |
| Last Updated | 2026-02-15 14:00 GMT |
Overview
Pydantic model representing the function specification within a V2 tool definition, including name, description, and JSON Schema parameters.
Description
ToolV2Function defines the function metadata for a V2 tool. It contains a required name field identifying the function, an optional description field explaining what the function does, and a required parameters field that holds a JSON Schema dictionary describing the function's input parameters. This model is referenced by ToolV2 (which wraps it under the function field with type="function") and is the primary way to declare tool capabilities when calling V2Client.chat() or V2Client.chat_stream(). The class extends UncheckedBaseModel with extra="allow" for forward compatibility.
Usage
Use ToolV2Function when building tool definitions for the Cohere V2 chat API. Each tool passed to the tools parameter of client.chat() should be a ToolV2 instance containing a ToolV2Function that describes the callable function's name, purpose, and parameter schema. The parameters field follows standard JSON Schema conventions (with "type", "properties", and "required" keys).
Code Reference
Source Location
- Repository: Cohere Python SDK
- File:
src/cohere/types/tool_v2function.pyLines L1-36
Signature
class ToolV2Function(UncheckedBaseModel):
"""The function to be executed."""
name: str = pydantic.Field()
description: typing.Optional[str] = pydantic.Field(default=None)
parameters: typing.Dict[str, typing.Any] = pydantic.Field()
Import
from cohere import ToolV2Function
I/O Contract
Fields
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
| name | str |
Yes | (none) | The name of the function. |
| description | Optional[str] |
No | None |
The description of the function. |
| parameters | Dict[str, Any] |
Yes | (none) | The parameters of the function as a JSON schema. |
Configuration
| Setting | Value | Description |
|---|---|---|
| extra | "allow" |
Permits additional fields not defined in the schema, ensuring forward compatibility. |
| smart_union | True |
Pydantic V1 only: enables smart union type resolution. |
Usage Examples
from cohere import ToolV2, ToolV2Function
# Define a tool with a ToolV2Function specification
tools = [
ToolV2(
function=ToolV2Function(
name="get_weather",
description="Get the current weather for a given location",
parameters={
"type": "object",
"properties": {
"location": {
"type": "string",
"description": "The city and state, e.g. San Francisco, CA",
},
"unit": {
"type": "string",
"enum": ["celsius", "fahrenheit"],
"description": "Temperature unit",
},
},
"required": ["location"],
},
)
),
]
# Pass tools to V2 chat
response = client.chat(
model="command-a-03-2025",
messages=[{"role": "user", "content": "What is the weather in Boston?"}],
tools=tools,
)
Related Pages
- Implementation:Cohere_ai_Cohere_python_ToolV2_Definition -- Parent ToolV2 model that wraps ToolV2Function
- Implementation:Cohere_ai_Cohere_python_ToolCallV2_Model -- Tool call response model returned when the model invokes a tool
- Implementation:Cohere_ai_Cohere_python_ToolParameterDefinitionsValue_Model -- Legacy V1 parameter definition model
- Implementation:Cohere_ai_Cohere_python_Tool_Execution_Pattern -- End-to-end tool execution pattern
- Environment:Cohere_ai_Cohere_python_Python_SDK_Runtime