Skip to content

Improved deserialization of AI citation models - #606

Merged
Rodrigo Brandão (rodrigobr-msft) merged 4 commits into
mainfrom
users/robrandao/client-citation-issue
Sep 28, 2026
Merged

Rodrigo Brandão (rodrigobr-msft) merged 4 commits into
mainfrom
users/robrandao/client-citation-issue

Conversation

@rodrigobr-msft

@rodrigobr-msft Rodrigo Brandão (rodrigobr-msft) commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

This pull request improves the serialization and deserialization of schema.org-style @id, @type, and @context fields in entity models, ensuring that these fields are handled consistently and only included when defined in the model. It also adds comprehensive tests to verify the correct behavior for models with and without an at_id field.

Enhancements to schema field serialization/deserialization:

  • Refactored the handling of @type, @context, and @id fields in _schema_mixin.py by introducing helper functions _deserialize_at_field and _serialize_at_field, ensuring these fields are only set or serialized if defined in the model or if extra fields are allowed. This prevents unintended attributes from being added to models.
  • Updated validate_schema_model and serialize_schema_model to use the new helper functions, improving maintainability and correctness of schema field processing.

Model updates:

  • Added an optional at_id field to the ClientCitation model to support deserialization and serialization of the @id property.

Testing improvements:

  • Added tests to verify that models without an at_id field ignore the @id property during (de)serialization, and that models with at_id handle it correctly. Also added tests for nested deserialization scenarios (e.g., Activity containing a ClientCitation).
  • Included missing import of Activity in the serialization test module to support new tests.

Copilot AI left a comment

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.

Copilot review overview

🟡 Changes recommended

Schema values currently bypass Pydantic validation, and the new deserialization helper is an unused no-op.

Review effort: Balanced
Findings: 1 Medium severity · 1 Low severity

Open (2)
What changed in this PR

Improves schema.org field handling for AI citation entities.

Changes:

  • Adds optional @id support to ClientCitation.
  • Refactors schema-field serialization and deserialization.
  • Adds direct and nested citation tests.
File Description
_schema_mixin.py Refactors @type, @context, and @id handling.
ai_entity.py Adds at_id to ClientCitation.
test_serialization.py Tests schema-ID handling and nested deserialization.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Copilot AI left a comment

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.

Copilot review overview

🔵 Needs a closer look

Schema aliases are no longer emitted for programmatically supplied fields on models that allow extras.

Review effort: Balanced
Findings: None

Resolved since last review (2)
Previously missed (1)

In code that hasn't changed since last review

Medium severity Preserve schema aliases for programmatically supplied extra fields

libraries/​microsoft-agents-activity/​microsoft_agents/​activity/​entity/​_schema_mixin.py:66

This drops schema aliases for programmatically supplied extras. Entity allows extra fields and uses this serializer, so Entity(type="custom", at_id="schema-id").model_dump(by_alias=True) previously included "@id" but now emits only the ordinary atId extra. The validator explicitly treats schema fields as valid when extras are allowed, so serialization should retain that same path rather than returning solely because the field is not declared.

@rodrigobr-msft
Rodrigo Brandão (rodrigobr-msft) merged commit e804862 into main Sep 28, 2026
10 checks passed
@rodrigobr-msft
Rodrigo Brandão (rodrigobr-msft) deleted the users/robrandao/client-citation-issue branch September 28, 2026 21:13
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.

ClientCitation deserialization fails when Copilot Studio citation contains @id: "ClientCitation" object has no field "at_id"

3 participants