diff --git a/litellm/proxy/guardrails/anthropic_sse.py b/litellm/proxy/guardrails/anthropic_sse.py index 3471d10330f..50c05daee11 100644 --- a/litellm/proxy/guardrails/anthropic_sse.py +++ b/litellm/proxy/guardrails/anthropic_sse.py @@ -98,15 +98,13 @@ def model_response_text(response: ModelResponse) -> str: ) -def anthropic_sse_error_frames(message: str | Mapping[str, object]) -> tuple[bytes, ...]: +def anthropic_sse_error_frames(message: str) -> tuple[bytes, ...]: """Anthropic error event, for a failure discovered after the response headers were flushed. Once a keepalive ping has been sent a raise cannot reach the client, so the failure has to - travel as a frame. A structured detail is JSON-serialized into the string so it stays machine - readable without violating the string-typed contract. + travel as a frame. """ - text: Final = message if isinstance(message, str) else json.dumps(message, default=str) - body: Final = json.dumps(text) + body: Final = json.dumps(message) return ( f'event: error\ndata: {{"type": "error", "error": {{"type": "guardrail_error", ' f'"message": {body}}}}}\n\n'.encode(), diff --git a/litellm/proxy/guardrails/guardrail_hooks/bedrock_guardrails.py b/litellm/proxy/guardrails/guardrail_hooks/bedrock_guardrails.py index b7bd4884ff0..293bb5ae8a0 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/bedrock_guardrails.py +++ b/litellm/proxy/guardrails/guardrail_hooks/bedrock_guardrails.py @@ -2639,13 +2639,9 @@ class BedrockGuardrail(CustomGuardrail, BaseAWSLLM): return except ModifyResponseException as e: if raw_sse: - # the shared per-endpoint block builder the unified guardrail path uses; it - # mints a fresh message id because the block is not the upstream message, but - # it reports exc.model, which defaults to the guardrail name rather than the model - e.model = _pre_block_response.model or e.model # rebind-ok: local synthetic block payload + e.model = _pre_block_response.model or e.model # rebind-ok: exc.model defaults to the guardrail if e.original_response is None: - # the builder reads usage off this; the upstream call was already paid for - e.original_response = _pre_block_response # rebind-ok: local synthetic block payload + e.original_response = _pre_block_response # rebind-ok: the block builder reads usage off this for block_chunk in AnthropicMessagesHandler().build_block_sse_chunks(e, stream_started=False): yield block_chunk return