Skip to content

Add Runtime Validation for name Attribute in Agent Class #1050

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from

Conversation

EngineerAbdullahIqbal
Copy link

This pull request proposes adding runtime validation to the Agent class in the openai-agents-sdk to ensure the name attribute is a non-empty string. This change addresses the issue where non-string types (e.g., integers or dictionaries) are currently accepted, despite the str type annotation, which can lead to unexpected behavior. By implementing validation, we make the SDK more robust and user-friendly.

Proposed Change

The proposed solution adds a __post_init__ method to the Agent class to validate that name is a string and not empty or whitespace-only. This approach is standard for Python dataclasses and does not affect other attributes or methods.

Why It Matters

This change prevents potential errors, aligns with type annotations, and improves the user experience by providing clear feedback on invalid inputs. It benefits the community by making the SDK more reliable, encouraging adoption, and reducing support overhead.

The __post_init__ method is the most suitable, as it is lightweight, aligns with Python dataclass conventions, and requires minimal changes to the existing codebase.

@seratch seratch added duplicate This issue or pull request already exists enhancement New feature or request feature:core labels Jul 10, 2025
@seratch
Copy link
Member

seratch commented Jul 10, 2025

Thanks for sending this PR! but we're already working on this at #998; please feel free to add comments if you have any.

@seratch seratch closed this Jul 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists enhancement New feature or request feature:core
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants