Commit cd48cd4
fix: populate required fields in FunctionDeclaration json_schema fallback
When _parse_schema_from_parameter raises ValueError for complex union
types (e.g. list[str] | None), from_function_with_options falls back to
the parameters_json_schema branch. This branch was missing two things:
1. The _get_required_fields() call to populate declaration.parameters.required
2. Default value propagation from inspect.Parameter to Schema.default/nullable
Without these, the LLM sees all parameters as optional and may omit
required ones.
This fix:
- Adds _get_required_fields() to the elif branch (mirrors primary path)
- Propagates non-None defaults to schema.default
- Sets schema.nullable=True for parameters defaulting to None
Includes regression test with list[str] | None parameter type.
Fixes #4798
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent 31b005c commit cd48cd4
File tree
2 files changed
+43
-0
lines changed- src/google/adk/tools
- tests/unittests/tools
2 files changed
+43
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
368 | 368 | | |
369 | 369 | | |
370 | 370 | | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
371 | 376 | | |
372 | 377 | | |
373 | 378 | | |
| |||
392 | 397 | | |
393 | 398 | | |
394 | 399 | | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
395 | 405 | | |
396 | 406 | | |
397 | 407 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
319 | 319 | | |
320 | 320 | | |
321 | 321 | | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
0 commit comments