Skip to content

Commit 014750b

Browse files
authored
fix(strict_schema): correct error message and replace runtime assert
This commit addresses two critical issues in the strict schema validation: 1. **Corrected error message for additionalProperties**: - Changed the misleading error message from "additionalProperties should not be set" to "additionalProperties should be set to False" - This accurately reflects the requirement that object types must explicitly set `additionalProperties: false` rather than implying it shouldn't be set at all - Prevents confusion for users encountering this validation error 2. **Replaced dangerous assert with proper exception handling**: - Replaced the `assert is_dict(value)` statement with proper runtime validation - Now raises a `ValueError` with clear message instead of relying on `assert` - Ensures validation works properly in optimized Python environments (when run with `-O` flag) - Maintains the same error semantics while making the code production-safe Both fixes maintain backward compatibility while improving error clarity and runtime safety.
1 parent d9f1d5f commit 014750b

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/agents/strict_schema.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def _ensure_strict_json_schema(
5757
and json_schema["additionalProperties"]
5858
):
5959
raise UserError(
60-
"additionalProperties should not be set for object types. This could be because "
60+
"additionalProperties should be set to False for object types. This could be because "
6161
"you're using an older version of Pydantic, or because you configured additional "
6262
"properties to be allowed. If you really need this, update the function or output tool "
6363
"to not use a strict schema."
@@ -154,9 +154,8 @@ def resolve_ref(*, root: dict[str, object], ref: str) -> object:
154154
resolved = root
155155
for key in path:
156156
value = resolved[key]
157-
assert is_dict(value), (
158-
f"encountered non-dictionary entry while resolving {ref} - {resolved}"
159-
)
157+
if not is_dict(value):
158+
raise ValueError(f"encountered non-dictionary entry while resolving {ref} - {resolved}")
160159
resolved = value
161160

162161
return resolved

0 commit comments

Comments
 (0)