|
1 | 1 | from __future__ import annotations as _annotations
|
2 | 2 |
|
3 | 3 | import base64
|
| 4 | +import warnings |
4 | 5 | from collections.abc import AsyncIterator, Sequence
|
5 | 6 | from contextlib import asynccontextmanager
|
6 | 7 | from dataclasses import dataclass, field, replace
|
@@ -776,6 +777,22 @@ def __init__(self, schema: JsonSchema):
|
776 | 777 | super().__init__(schema, prefer_inlined_defs=True, simplify_nullable_unions=True)
|
777 | 778 |
|
778 | 779 | def transform(self, schema: JsonSchema) -> JsonSchema:
|
| 780 | + # Note: we need to remove `additionalProperties: False` since it is currently mishandled by Gemini |
| 781 | + additional_properties = schema.pop( |
| 782 | + 'additionalProperties', None |
| 783 | + ) # don't pop yet so it's included in the warning |
| 784 | + if additional_properties: # pragma: no cover |
| 785 | + original_schema = {**schema, 'additionalProperties': additional_properties} |
| 786 | + warnings.warn( |
| 787 | + '`additionalProperties` is not supported by Gemini; it will be removed from the tool JSON schema.' |
| 788 | + f' Full schema: {self.schema}\n\n' |
| 789 | + f'Source of additionalProperties within the full schema: {original_schema}\n\n' |
| 790 | + 'If this came from a field with a type like `dict[str, MyType]`, that field will always be empty.\n\n' |
| 791 | + "If Google's APIs are updated to support this properly, please create an issue on the PydanticAI GitHub" |
| 792 | + ' and we will fix this behavior.', |
| 793 | + UserWarning, |
| 794 | + ) |
| 795 | + |
779 | 796 | schema.pop('title', None)
|
780 | 797 | schema.pop('default', None)
|
781 | 798 | schema.pop('$schema', None)
|
|
0 commit comments