Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyrit/models/json_response_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def from_metadata(cls, *, metadata: Optional[dict[str, Any]]) -> _JsonResponseCo
return cls(enabled=False)

schema_val = metadata.get(_METADATAKEYS["JSON_SCHEMA"])
if schema_val:
if schema_val is not None:
if isinstance(schema_val, str):
try:
schema = json.loads(schema_val) if schema_val else None
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/models/test_json_response_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ def test_with_json_schema_object():
assert config.strict is True


def test_with_empty_json_schema_object():
metadata = {
"response_format": "json",
"json_schema": {},
}
config = _JsonResponseConfig.from_metadata(metadata=metadata)
assert config.enabled is True
assert config.schema == {}
assert config.schema_name == "CustomSchema"
assert config.strict is True


def test_with_invalid_json_schema_string():
metadata = {
"response_format": "json",
Expand Down
Loading