Skip to content

Commit 5811b8a

Browse files
authored
Preserve empty JSON schema metadata (#1488)
1 parent 927ad88 commit 5811b8a

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

pyrit/models/json_response_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def from_metadata(cls, *, metadata: Optional[dict[str, Any]]) -> _JsonResponseCo
4242
return cls(enabled=False)
4343

4444
schema_val = metadata.get(_METADATAKEYS["JSON_SCHEMA"])
45-
if schema_val:
45+
if schema_val is not None:
4646
if isinstance(schema_val, str):
4747
try:
4848
schema = json.loads(schema_val) if schema_val else None

tests/unit/models/test_json_response_config.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,18 @@ def test_with_json_schema_object():
5555
assert config.strict is True
5656

5757

58+
def test_with_empty_json_schema_object():
59+
metadata = {
60+
"response_format": "json",
61+
"json_schema": {},
62+
}
63+
config = _JsonResponseConfig.from_metadata(metadata=metadata)
64+
assert config.enabled is True
65+
assert config.schema == {}
66+
assert config.schema_name == "CustomSchema"
67+
assert config.strict is True
68+
69+
5870
def test_with_invalid_json_schema_string():
5971
metadata = {
6072
"response_format": "json",

0 commit comments

Comments
 (0)