Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/+.bugfix.2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Disallow null values for optional fields in generated GenAI JSON schemas.
36 changes: 18 additions & 18 deletions docs/gen-ai/non-normative/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import json
from enum import StrEnum
from pathlib import Path
from typing import Annotated, Any, List, Literal, Optional, Union
from typing import Annotated, Any, List, Literal, Union

from pydantic import (
BaseModel,
Expand Down Expand Up @@ -63,7 +63,7 @@ class ToolCallRequestPart(BaseModel):
type: Literal["tool_call"] = Field(
description="The type of the content captured in this part."
)
id: Optional[str] = Field(
id: str = Field(
default=None, description="Unique identifier for the tool call."
)
name: str = Field(description="Name of the tool.")
Expand All @@ -80,7 +80,7 @@ class ToolCallResponsePart(BaseModel):
type: Literal["tool_call_response"] = Field(
description="The type of the content captured in this part."
)
id: Optional[str] = Field(default=None, description="Unique tool call identifier.")
id: str = Field(default=None, description="Unique tool call identifier.")
response: Any = Field(description="Tool call response.")

model_config = ConfigDict(extra="allow")
Expand Down Expand Up @@ -122,7 +122,7 @@ class ServerToolCallPart(BaseModel):
type: Literal["server_tool_call"] = Field(
description="The type of the content captured in this part."
)
id: Optional[str] = Field(
id: str = Field(
default=None, description="Unique identifier for the server tool call."
)
name: str = Field(description="Name of the server tool.")
Expand All @@ -139,7 +139,7 @@ class ServerToolCallResponsePart(BaseModel):
type: Literal["server_tool_call_response"] = Field(
description="The type of the content captured in this part."
)
id: Optional[str] = Field(
id: str = Field(
default=None,
description="Unique server tool call identifier matching the original call.",
)
Expand Down Expand Up @@ -180,11 +180,11 @@ class CompactionPart(BaseModel):
type: Literal["compaction"] = Field(
description="The type of the content captured in this part."
)
id: Optional[str] = Field(
id: str = Field(
default=None,
description="Provider-assigned identifier for the compaction item or block.",
)
content: Optional[str] = Field(
content: str = Field(
default=None,
description="The unencrypted compacted conversation summary, when available.",
)
Expand All @@ -198,7 +198,7 @@ class BlobPart(BaseModel):
type: Literal["blob"] = Field(
description="The type of the content captured in this part."
)
mime_type: Optional[str] = Field(
mime_type: str = Field(
default=None, description="The IANA MIME type of the attached data."
)
modality: Union[Modality, str] = Field(
Expand All @@ -215,7 +215,7 @@ class FilePart(BaseModel):
type: Literal["file"] = Field(
description="The type of the content captured in this part."
)
mime_type: Optional[str] = Field(
mime_type: str = Field(
default=None, description="The IANA MIME type of the attached data."
)
modality: Union[Modality, str] = Field(
Expand All @@ -234,7 +234,7 @@ class UriPart(BaseModel):
type: Literal["uri"] = Field(
description="The type of the content captured in this part."
)
mime_type: Optional[str] = Field(
mime_type: str = Field(
default=None, description="The IANA MIME type of the attached data."
)
modality: Union[Modality, str] = Field(
Expand Down Expand Up @@ -304,7 +304,7 @@ class ChatMessage(BaseModel):
parts: List[MessagePart] = Field(
description="List of message parts that make up the message content."
)
name: Optional[str] = Field(
name: str = Field(
default=None, description="The name of the participant."
)

Expand Down Expand Up @@ -417,15 +417,15 @@ class FunctionToolDefinition(GenericToolDefinition):
"""

type: Literal["function"] = Field(description="The type of the tool.")
description: Optional[str] = Field(
description: str = Field(
default=None,
description=(
"The description of the tool. "
"Since this attribute could be large, it's NOT RECOMMENDED to be populated by default. "
"Instrumentations MAY provide a way to enable populating this property."
),
)
parameters: Optional[JsonSchemaDraft7Dict] = Field(
parameters: JsonSchemaDraft7Dict = Field(
default=None,
description=(
Comment on lines 430 to 441

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 136ff7e. Added a shared omittable_field helper that preserves the runtime default while omitting default: null from the generated schema, keeping the omittable/non-nullable contract consistent.

"JSON Schema document describing the parameters accepted by the tool. "
Expand Down Expand Up @@ -464,10 +464,10 @@ class RetrievalDocument(BaseModel):
Represents a single document retrieved from a vector database or search system.
"""

id: str | None = Field(
id: str = Field(
default=None, description="A unique identifier for the document."
)
score: float | None = Field(
score: float = Field(
default=None, description="The relevance score of the document."
)

Expand Down Expand Up @@ -495,14 +495,14 @@ class MemoryRecord(BaseModel):
"""

content: Any = Field(description="The content of the memory record.")
id: Optional[str] = Field(
id: str = Field(
default=None, description="A unique identifier for the memory record."
)
metadata: Optional[dict[str, Any]] = Field(
metadata: dict[str, Any] = Field(
default=None,
description="Provider-specific metadata associated with the memory record.",
)
score: Optional[float] = Field(
score: float = Field(
default=None,
description="The relevance score of the memory record when populated on search results.",
)
Expand Down
110 changes: 20 additions & 90 deletions model/gen-ai/gen-ai-input-messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,10 @@
"type": "string"
},
"mime_type": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "The IANA MIME type of the attached data.",
"title": "Mime Type"
"title": "Mime Type",
"type": "string"
},
"modality": {
"anyOf": [
Expand Down Expand Up @@ -107,17 +100,10 @@
"type": "array"
},
"name": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "The name of the participant.",
"title": "Name"
"title": "Name",
"type": "string"
}
},
"required": [
Expand All @@ -138,30 +124,16 @@
"type": "string"
},
"id": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "Provider-assigned identifier for the compaction item or block.",
"title": "Id"
"title": "Id",
"type": "string"
},
"content": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "The unencrypted compacted conversation summary, when available.",
"title": "Content"
"title": "Content",
"type": "string"
}
},
"required": [
Expand All @@ -181,17 +153,10 @@
"type": "string"
},
"mime_type": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "The IANA MIME type of the attached data.",
"title": "Mime Type"
"title": "Mime Type",
"type": "string"
},
"modality": {
"anyOf": [
Expand Down Expand Up @@ -321,17 +286,10 @@
"type": "string"
},
"id": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "Unique identifier for the server tool call.",
"title": "Id"
"title": "Id",
"type": "string"
},
"name": {
"description": "Name of the server tool.",
Expand Down Expand Up @@ -362,17 +320,10 @@
"type": "string"
},
"id": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "Unique server tool call identifier matching the original call.",
"title": "Id"
"title": "Id",
"type": "string"
},
"server_tool_call_response": {
"$ref": "#/$defs/GenericServerToolCallResponse",
Expand Down Expand Up @@ -420,17 +371,10 @@
"type": "string"
},
"id": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "Unique identifier for the tool call.",
"title": "Id"
"title": "Id",
"type": "string"
},
"name": {
"description": "Name of the tool.",
Expand Down Expand Up @@ -461,17 +405,10 @@
"type": "string"
},
"id": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "Unique tool call identifier.",
"title": "Id"
"title": "Id",
"type": "string"
},
"response": {
"description": "Tool call response.",
Expand All @@ -496,17 +433,10 @@
"type": "string"
},
"mime_type": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "The IANA MIME type of the attached data.",
"title": "Mime Type"
"title": "Mime Type",
"type": "string"
},
"modality": {
"anyOf": [
Expand Down
35 changes: 7 additions & 28 deletions model/gen-ai/gen-ai-memory-records.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,44 +9,23 @@
"title": "Content"
},
"id": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "A unique identifier for the memory record.",
"title": "Id"
"title": "Id",
"type": "string"
},
"metadata": {
"anyOf": [
{
"additionalProperties": true,
"type": "object"
},
{
"type": "null"
}
],
"additionalProperties": true,
"default": null,
"description": "Provider-specific metadata associated with the memory record.",
"title": "Metadata"
"title": "Metadata",
"type": "object"
},
"score": {
"anyOf": [
{
"type": "number"
},
{
"type": "null"
}
],
"default": null,
"description": "The relevance score of the memory record when populated on search results.",
"title": "Score"
"title": "Score",
"type": "number"
Comment on lines +13 to +25

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 136ff7e. The generated memory-record fields are omittable, non-nullable, and no longer advertise a null default.

}
},
"required": [
Expand Down
Loading
Loading