diff --git a/litellm/proxy/utils.py b/litellm/proxy/utils.py index 03a481e3eab..53092b5d8c9 100644 --- a/litellm/proxy/utils.py +++ b/litellm/proxy/utils.py @@ -1917,6 +1917,16 @@ async def _skipped_for_unroutable_model( _SYSTEM_INSTRUCTION_KEYS: Final = ("systemInstruction", "system_instruction") +_EXTRACTION_SPEC_TEXT_KEYS: Final = ("instructions", "unit") + + +def _without_extraction_spec_texts(spec: object) -> object: + spec_fields: Final = _as_str_mapping(spec) + return ( + spec + if not isinstance(spec, Mapping) + else {**spec_fields, **{key: REDACTED_BY_LITELLM for key in _EXTRACTION_SPEC_TEXT_KEYS if key in spec_fields}} + ) def without_unscanned_content(request: Mapping[str, object]) -> Mapping[str, object]: @@ -1929,6 +1939,7 @@ def without_unscanned_content(request: Mapping[str, object]) -> Mapping[str, obj "input": "", "query": "", "instruction": "", + "state": "", "tools": [], "system": REDACTED_BY_LITELLM, "instructions": REDACTED_BY_LITELLM, @@ -1936,8 +1947,15 @@ def without_unscanned_content(request: Mapping[str, object]) -> Mapping[str, obj } config: Final = request.get("config") config_fields: Final = _as_str_mapping(config) + extraction_fields: Final = request.get("fields") + extraction_specs: Final = _as_str_mapping(extraction_fields) return { **{key: value for key, value in redactions.items() if key in request}, + **( + {} + if not isinstance(extraction_fields, Mapping) + else {"fields": {name: _without_extraction_spec_texts(spec) for name, spec in extraction_specs.items()}} + ), **( {} if not isinstance(config, Mapping) diff --git a/tests/unit/proxy/test_proxy_utils.py b/tests/unit/proxy/test_proxy_utils.py index b1e011d92ee..11e7335a309 100644 --- a/tests/unit/proxy/test_proxy_utils.py +++ b/tests/unit/proxy/test_proxy_utils.py @@ -3901,6 +3901,8 @@ def test_without_unscanned_content_redacts_every_field_a_guardrail_can_rewrite() "input": ["card 4111"], "query": "card 4111", "instruction": "card 4111", + "state": "card 4111", + "fields": {"card": {"type": "string", "instructions": "card 4111", "unit": "card 4111"}}, "tools": [{"type": "function", "function": {"name": "card", "description": "4111"}}], "system": "card 4111", "instructions": "card 4111", @@ -3915,6 +3917,8 @@ def test_without_unscanned_content_redacts_every_field_a_guardrail_can_rewrite() "input": "", "query": "", "instruction": "", + "state": "", + "fields": {"card": {"type": "string", "instructions": REDACTED_BY_LITELLM, "unit": REDACTED_BY_LITELLM}}, "tools": [], "system": REDACTED_BY_LITELLM, "instructions": REDACTED_BY_LITELLM,