fix(guardrails): type the request payload handed to the Anthropic write-back

This commit is contained in:
mateo-berri 2026-09-14 21:28:47 -07:00
parent 8b80971586
commit ae90f1a458
2 changed files with 5 additions and 4 deletions

View file

@ -1079,14 +1079,15 @@ class AnthropicMessagesHandler(BaseTranslation):
async def _apply_guardrail_responses_to_input(
self,
data: dict,
responses: list[str],
data: dict[str, object], # mutable-ok: API message payload
responses: Sequence[str],
scanned: tuple[ScannedText, ...],
) -> None:
"""
Apply guardrail responses back to the top-level system prompt and the input messages.
"""
messages: Final[Sequence[_WritableMessage]] = data.get("messages") or ()
raw_messages: Final = data.get("messages")
messages: Final[Sequence[_WritableMessage]] = raw_messages if isinstance(raw_messages, list) else ()
for item, guardrail_response in zip(scanned, responses):
match item.target:
case SystemStringTarget():

View file

@ -2200,7 +2200,7 @@ class TestAnthropicMessagesTopLevelSystemAndToolUseInputs:
inputs, the same way the chat completions handler hands over system messages and tool_calls."""
@staticmethod
def _tool_use_conversation(system):
def _tool_use_conversation(system: str) -> dict[str, Any]:
return {
"model": "claude-sonnet-4-5",
"system": system,