diff --git a/pyrit/models/json_response_config.py b/pyrit/models/json_response_config.py index 9ddb914ed..8485467cf 100644 --- a/pyrit/models/json_response_config.py +++ b/pyrit/models/json_response_config.py @@ -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 diff --git a/tests/unit/models/test_json_response_config.py b/tests/unit/models/test_json_response_config.py index d91c4bd54..e555a0db4 100644 --- a/tests/unit/models/test_json_response_config.py +++ b/tests/unit/models/test_json_response_config.py @@ -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",