mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-15 09:12:18 +00:00
fix(proxy): redact extraction state and field texts a skipped guardrail would have scanned
This commit is contained in:
parent
7cdf7fcfd7
commit
ce788bc180
2 changed files with 22 additions and 0 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue