Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: Enforce strict validation for message parts and forbid extra fields
  • Loading branch information
Łukasz Bobiński committed Feb 4, 2026
commit 2ed52de6aecb68831a7c4ce602d0b3cff6140f82
1 change: 1 addition & 0 deletions src/a2a/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ class A2ABaseModel(BaseModel):
validate_by_alias=True,
serialize_by_alias=True,
alias_generator=to_camel_custom,
extra='forbid',
)
39 changes: 39 additions & 0 deletions tck/sut_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@
TaskStatus,
TaskStatusUpdateEvent,
TextPart,
FilePart,
DataPart,
InvalidParamsError,
)
from a2a.utils.errors import ServerError


JSONRPC_URL = '/a2a/jsonrpc'
Expand Down Expand Up @@ -67,6 +71,41 @@ async def execute(
task_id = context.task_id
context_id = context.context_id

# Validate message parts
if not user_message.parts:
# Empty parts array is invalid
raise ServerError(
error=InvalidParamsError(message='Message must contain at least one part')
)

for part in user_message.parts:
# Unwrap RootModel if present to get the actual part
actual_part = part
if hasattr(part, 'root'):
actual_part = part.root
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

low

There's a minor indentation issue here. This line has an extra space at the beginning. Please correct it for code style consistency.

Suggested change
actual_part = part.root
actual_part = part.root


# Check if it's a known part type
if not isinstance(actual_part, (TextPart, FilePart, DataPart)):
# If we received something that isn't a known part, treating it as unsupported.
# Enqueue a failed status event.
await event_queue.enqueue_event(TaskStatusUpdateEvent(
task_id=task_id,
context_id=context_id,
status=TaskStatus(
state=TaskState.failed,
message=Message(
role='agent',
message_id=str(uuid.uuid4()),
parts=[TextPart(text='Unsupported message part type')],
task_id=task_id,
context_id=context_id,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

low

The task_id and context_id fields are already present in the parent TaskStatusUpdateEvent object. Including them again in this nested Message object is redundant. Consider removing them to improve code clarity and avoid data duplication.

),
timestamp=datetime.now(timezone.utc).isoformat(),
),
final=True,
))
return

self.running_tasks.add(task_id)

logger.info(
Expand Down