Migrate output types from dataclasses to Pydantic for validation #827
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Replaces dataclasses with Pydantic BaseModel for all output type definitions to enable better validation and maintain compatibility with existing code.
Changes
Core Infrastructure
@dataclassto PydanticBaseModelmodel_configwitharbitrary_types_allowed,extra='allow', andpopulate_by_name=True__getattribute__and__setattr__for backward compatibility with underscore-prefixed fields (_source,_type,_timestamp, etc.)toDict()to usemodel_dump()andkeys()to usemodel_fieldsload()method to iterate overmodel_fieldsinstead offields()Field Aliasing Pattern
Pydantic v2 disallows field names starting with underscores. All underscore-prefixed fields now use aliases:
Output Type Classes
field()withField()for factory defaults_table_fields,_sort_by) outside class definitions__post_init__methods to@model_validator(mode='after')decoratorsSupporting Changes
model_fields.keys()instead offields()Dict,List,Optional) across all output typesCompatibility
All existing code accessing output type attributes continues to work without modification. The custom attribute handlers transparently map
item._sourcetoitem.source_internally.Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.