FunctionDeclaration.from_callable drops enum and properties from Optional[...] parameters
Maintainer thường phản hồi trong vòng 1 ngày
@Venkaiahbabuneelam đang làm issue này rồi.
Từ ngày 13/10/2026.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 67/100
Hướng nghiên cứu
Đọc _automatic_function_calling_util.py quanh _parse_schema_from_parameter và phần gộp Union có một thành viên gần dòng 282. So sánh Optional và pipe-union examples trong issue, rồi thêm các trường hợp hồi quy vào tests/types/test_types.py cho tham số Literal tùy chọn và tham số model tùy chọn. Hoàn tất khi các schema được tạo vẫn giữ các thuộc tính enum hoặc object, đồng thời vẫn nullable.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
FunctionDeclaration.from_callable keeps only the type of the inner schema when a parameter is Optional[X]. An Optional[Literal["c", "f"]] parameter becomes a nullable string with no enum. An Optional[Address] parameter becomes a bare nullable object with no properties or required. Address | None keeps them, but Literal["c", "f"] | None loses its enum too.
import json
from typing import Literal, Optional
import pydantic
from google import genai
from google.genai import types
client = genai.Client(api_key="not-a-real-key") # no request is sent
class Address(pydantic.BaseModel):
city: str
def unit_plain(unit: Literal["c", "f"]) -> str: ...
def unit_optional(unit: Optional[Literal["c", "f"]] = None) -> str: ...
def addr_optional(addr: Optional[Address] = None) -> str: ...
def addrs_optional(addrs: Optional[list[Address]] = None) -> str: ...
def unit_pipe(unit: Literal["c", "f"] | None = None) -> str: ...
def addr_pipe(addr: Address | None = None) -> str: ...
for f in [unit_plain, unit_optional, addr_optional, addrs_optional, unit_pipe, addr_pipe]:
fd = types.FunctionDeclaration.from_callable(client=client, callable=f)
(name, s), = fd.parameters.properties.items()
print(f"{f.__name__:15}", json.dumps(s.model_dump(exclude_none=True)))
$ python -I genai_fd3.py
unit_plain {"enum": ["c", "f"], "type": "STRING"}
unit_optional {"nullable": true, "type": "STRING"}
addr_optional {"nullable": true, "type": "OBJECT"}
addrs_optional {"items": {"properties": {"city": {"type": "STRING"}}, "required": ["city"], "type": "OBJECT"}, "nullable": true, "type": "ARRAY"}
unit_pipe {"nullable": true, "type": "STRING"}
addr_pipe {"nullable": true, "properties": {"city": {"type": "STRING"}}, "required": ["city"], "type": "OBJECT"}
# google-genai 2.29.0 at 6a6501c (main, 2026-10-11), CPython 3.12.3, Linux x86_64
The single-member collapse in the Union branch of _parse_schema_from_parameter (_automatic_function_calling_util.py:282) copies schema.any_of[0].type and nothing else. Optional[list[...]] survives only because the lines above it copy items by hand. Copying the whole member fixes both:
if len(schema.any_of) == 1: # param: Union[List, None] -> Array
- schema.type = schema.any_of[0].type
- schema.any_of = None
+ schema = schema.any_of[0].model_copy(
+ update={'nullable': schema.nullable}
+ )
$ python -I genai_fd3.py # with the patch
unit_plain {"enum": ["c", "f"], "type": "STRING"}
unit_optional {"enum": ["c", "f"], "nullable": true, "type": "STRING"}
addr_optional {"nullable": true, "properties": {"city": {"type": "STRING"}}, "required": ["city"], "type": "OBJECT"}
addrs_optional {"items": {"properties": {"city": {"type": "STRING"}}, "required": ["city"], "type": "OBJECT"}, "nullable": true, "type": "ARRAY"}
unit_pipe {"enum": ["c", "f"], "nullable": true, "type": "STRING"}
addr_pipe {"nullable": true, "properties": {"city": {"type": "STRING"}}, "required": ["city"], "type": "OBJECT"}
$ python -m pytest -q google/genai/tests/types/test_types.py google/genai/tests/types/test_future.py
95 passed, 6 skipped, 2 warnings # same count before and after the patch
# not run: any request to the live API
This is the default use_json_schema=False path, so it hits direct from_callable callers. A function passed straight into tools=[...] takes use_json_schema=True (_transformers.py:961), where open #3074 and #3093 work. @Venkaiahbabuneelam, CONTRIBUTING.md says outside pull requests are not taken yet, so the diff above is the whole proposal. Would a test for these signatures in tests/types/test_types.py help it land?
- Ngôn ngữ chính
- Python
- Star
- 4k
- Fork
- 1k
- Merge trung bình
- 1 ngày 6 giờ
- Pull request đã merge (30 ngày)
- 88
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của googleapis/python-genai
-
Test import module that doesn't existCó thể đã có người làm @Venkaiahbabuneelam đã nhận hôm nay. Đang mởpriority: p2 status:awaiting user response type: bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
googleapis/python-genai#3122 · 3 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Curated history keeps half a user turn when the model turn is invalidCó thể đã có người làm @Venkaiahbabuneelam đã nhận 9 ngày trước. Đang mởpriority: p2 type: bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
googleapis/python-genai#3051 · 3 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug]: Unsubscripted typing.List and typing.Dict crash convert_if_exist_pydantic_model in AFCCó thể đã có người làm @Venkaiahbabuneelam đã nhận 9 ngày trước. Đang mởpriority: p2 type: bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
googleapis/python-genai#3044 · 1 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Name collision in google.genai.interactions: triggers.Interaction shadows response model Interaction in static type checkersCó thể đã có người làm @Venkaiahbabuneelam đã nhận 16 ngày trước. Đang mởpriority: p2 type: bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
googleapis/python-genai#3013 · 1 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Live API] Function declaration size degrades speech output (name pronunciation): is there a documented budget or design pattern?Có thể đã có người làm @Venkaiahbabuneelam đã nhận hôm nay. Đang mởpriority: p2 type: bug
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 8/100
googleapis/python-genai#3120 · 1 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của googleapis/python-genai
Issue tương tự
-
customer-reported question
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Azure/azure-sdk-for-python#49548 · 1 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
btclib-org/btclib-wallet#409 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Phase 2 PSA Capability & Career Profile
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
bcgov/digital-journeys#2310 ·
-
bug good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
fastmachinelearning/hls4ml#1582 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Sort modelsĐang mởenhancement good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày