Skip to content

fix: add typing.Annotated support to serialize_type/deserialize_type - #12351

Closed
yashrajrr wants to merge 1 commit into
deepset-ai:mainfrom
yashrajrr:fix/annotated-type-serialization
Closed

fix: add typing.Annotated support to serialize_type/deserialize_type#12351
yashrajrr wants to merge 1 commit into
deepset-ai:mainfrom
yashrajrr:fix/annotated-type-serialization

Conversation

@yashrajrr

Copy link
Copy Markdown

Fixes #12338 — Fix Annotated Type Serialization

Problem

typing.Annotated types were not correctly preserved by serialize_type() / deserialize_type().

  • String metadata lost quotes during serialization.
  • Deserialization could fail.
  • Metadata such as "int" could be incorrectly converted to the int type.
  • This affected pipeline save/load for components using Annotated type hints.

Changes

  • Added _parse_annotated_args() to correctly parse nested types, quoted strings, commas, and mixed quotes.
  • Use repr() when serializing Annotated metadata.
  • Use ast.literal_eval() for safe metadata deserialization.
  • Added tests for nested types, multiple metadata values, strings containing commas, Optional, and Union.
  • Added release note.

Tests

  • test_type_serialization.py: 198 tests passed
  • Full serialization suite: 476 tests passed
  • No breaking changes.

Target

deepset-ai/haystack:mainyashrajrr/haystack:fix/annotated-type-serialization

Fixes deepset-ai#12338 - Annotated types could not be round-tripped through
serialize_type/deserialize_type. Metadata values were rendered without
quotes causing deserialization failures or silent corruption.

Changes:
- Added _parse_annotated_args() for quote-aware metadata parsing
- serialize_type now uses repr() on metadata (strings keep quotes)
- deserialize_type uses ast.literal_eval for safe metadata parsing
- Added comprehensive test coverage
@yashrajrr
yashrajrr requested a review from a team as a code owner August 14, 2026 17:34
@yashrajrr
yashrajrr requested review from davidsbatista and removed request for a team August 14, 2026 17:34
@vercel

vercel Bot commented Aug 14, 2026

Copy link
Copy Markdown

@yashrajrr is attempting to deploy a commit to the deepset Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions

Copy link
Copy Markdown
Contributor

Hi @yashrajrr, thanks for your interest in contributing to Haystack! 🙏

⚠️ Issue #12338 is already being addressed by open pull request(s) #12339. Before opening a PR for an issue, please check whether a PR is already linked to it, and consider contributing to the existing PR instead. We may close duplicate PRs to keep the review queue manageable.

This is an automated message to help us keep the review queue healthy.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: serialize_type / deserialize_type do not support typing.Annotated

1 participant