litellm/llms/a2a/chat/guardrail_translation/README.md
Handler for processing A2A (Agent-to-Agent) Protocol messages with guardrails.
This handler processes A2A JSON-RPC 2.0 input/output by:
kind: "text"){
"jsonrpc": "2.0",
"id": "request-id",
"method": "message/send",
"params": {
"message": {
"kind": "message",
"messageId": "...",
"role": "user",
"parts": [
{"kind": "text", "text": "Hello, my SSN is 123-45-6789"}
]
},
"metadata": {
"guardrails": ["block-ssn"]
}
}
}
The handler supports multiple A2A response formats:
Direct message:
{
"result": {
"kind": "message",
"parts": [{"kind": "text", "text": "Response text"}]
}
}
Nested message:
{
"result": {
"message": {
"parts": [{"kind": "text", "text": "Response text"}]
}
}
}
Task with artifacts:
{
"result": {
"kind": "task",
"artifacts": [
{"parts": [{"kind": "text", "text": "Artifact text"}]}
]
}
}
Task with status message:
{
"result": {
"kind": "task",
"status": {
"message": {
"parts": [{"kind": "text", "text": "Status message"}]
}
}
}
}
Streaming artifact-update:
{
"result": {
"kind": "artifact-update",
"artifact": {
"parts": [{"kind": "text", "text": "Streaming text"}]
}
}
}
The handler is automatically discovered and applied when guardrails are used with A2A endpoints.
curl -X POST 'http://localhost:4000/a2a/my-agent' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer your-api-key' \
-d '{
"jsonrpc": "2.0",
"id": "1",
"method": "message/send",
"params": {
"message": {
"kind": "message",
"messageId": "msg-1",
"role": "user",
"parts": [{"kind": "text", "text": "Hello, my SSN is 123-45-6789"}]
},
"metadata": {
"guardrails": ["block-ssn"]
}
}
}'
Guardrails can be specified in the A2A request via the metadata.guardrails field:
{
"params": {
"message": {...},
"metadata": {
"guardrails": ["block-ssn", "pii-filter"]
}
}
}
Override these methods to customize behavior:
_extract_texts_from_result(): Custom text extraction from A2A responses_extract_texts_from_parts(): Custom text extraction from message parts_apply_text_to_path(): Custom application of guardrailed textThis handler is registered for:
CallTypes.send_message: Synchronous A2A message sendingCallTypes.asend_message: Asynchronous A2A message sending