From 1b36a6a5ffbf2b630bebf2e957d742afc7898041 Mon Sep 17 00:00:00 2001 From: biefan <70761325+biefan@users.noreply.github.com> Date: Tue, 17 Mar 2026 03:14:08 +0000 Subject: [PATCH] Preserve empty JSON schema metadata --- pyrit/models/json_response_config.py | 2 +- tests/unit/models/test_json_response_config.py | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) 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",