Skip to content

Conversation

@punkyoon
Copy link

@punkyoon punkyoon commented Feb 6, 2026

Description

Thank you for opening a Pull Request!
Before submitting your PR, there are a few things you can do to make sure it goes smoothly:

  • Follow the CONTRIBUTING Guide.
  • Make your Pull Request title in the https://www.conventionalcommits.org/ specification.
    • Important Prefixes for release-please:
      • fix: which represents bug fixes, and correlates to a SemVer patch.
      • feat: represents a new feature, and correlates to a SemVer minor.
      • feat!:, or fix!:, refactor!:, etc., which represent a breaking change (indicated by the !) and will result in a SemVer major.
  • Ensure the tests and linter pass (Run bash scripts/format.sh from the repository root to format)
  • Appropriate docs were updated (if necessary)

Fixes #670 🦕

Summary

This PR adds validation to the Artifact model in a2a/types.py to ensure that the parts list is never empty.

Motivation

According to the A2A Protocol Specification (Section 4.17), an Artifact's parts list "Must contain at least one part."

Previously, it was possible to initialize an Artifact with an empty list []. This discrepancy allowed invalid artifacts to be created (e.g., by strands-agents) which could cause issues for downstream consumers.

This change also aligns the Python SDK with the Java SDK, which already strictly enforces this rule (see a2a-java implementation).

Changes

  • Updated Artifact class in a2a/types.py.
  • Used Pydantic's Field(min_length=1) to enforce the constraint at the model level.

Verification

Attempting to create an Artifact with empty parts now raises a ValidationError:

from a2a.types import Artifact
import pytest
from pydantic import ValidationError

# This now raises ValidationError
with pytest.raises(ValidationError):
    Artifact(
        artifact_id="test-id",
        parts=[], 
        metadata={}
    )

@punkyoon punkyoon requested a review from a2a-bot as a code owner February 6, 2026 12:10
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @punkyoon, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical data integrity issue by ensuring that the parts list in the Artifact model is never empty. This change prevents the creation of invalid artifacts that do not conform to the A2A Protocol Specification, thereby enhancing the robustness of the system and aligning the Python SDK with the strict validation already present in the Java SDK.

Highlights

  • Artifact Model Validation: Enforced that the parts list within the Artifact model must contain at least one element, aligning with the A2A Protocol Specification (Section 4.17).
  • Pydantic min_length Constraint: Utilized Pydantic's Field(min_length=1) to implement the validation constraint directly in the Artifact model definition in a2a/types.py.
Changelog
  • src/a2a/types.py
    • Added a min_length=1 constraint to the parts field of the Artifact class, ensuring that an Artifact object always contains at least one Part.
Activity
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request aims to enforce that an Artifact must contain at least one part, which aligns with the A2A Protocol Specification. The implementation using Pydantic's Field(min_length=1) is functionally correct. However, there's a significant maintenance concern as the change is made to an auto-generated file (src/a2a/types.py). My review comment details why this change should be made in the source JSON schema instead to ensure it's not lost upon regeneration.

An optional, human-readable name for the artifact.
"""
parts: list[Part]
parts: list[Part] = Field(min_length=1)
Copy link
Contributor

Choose a reason for hiding this comment

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

high

While this change correctly enforces the min_length constraint, this file is marked as auto-generated by datamodel-codegen at the top. Manual edits to generated files are fragile and likely to be overwritten the next time the code generation script is run. To make this change permanent, the constraint should be added to the source JSON schema (likely as "minItems": 1 for the parts array within the Artifact definition) and then this Python model file should be regenerated.

Copy link
Author

Choose a reason for hiding this comment

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

I missed that types.py is automatically generated. I have opened an issue in the main repository to ensure the constraint is included during model generation: a2aproject/A2A#1456

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Enforce non-empty parts in Artifact model to match A2A Specification

1 participant