Skip to content

fix: preserve quoted Literal delimiters during type deserialization - #13055

Open
hulkbig wants to merge 1 commit into
deepset-ai:mainfrom
hulkbig:fix/literal-type-delimiters
Open

hulkbig wants to merge 1 commit into
deepset-ai:mainfrom
hulkbig:fix/literal-type-delimiters

Conversation

@hulkbig

@hulkbig hulkbig commented Oct 1, 2026

Copy link
Copy Markdown

Related Issues

No issue is linked. Independently reproduced on main at a5432b976f888678b61902a7fb999654a6384ef6.

This follows the Literal support added in #12286. The open #12339 handles Annotated metadata; it does not fix the existing generic-argument and PEP 604 scanners changed here.

Proposed Changes:

Type deserialization counts brackets and splits separators before reaching the quote-aware Literal parser. A bracket inside a string value can therefore be mistaken for type syntax. For example, this public component round trip currently fails:

from typing import Literal
from haystack.components.converters import OutputAdapter

adapter = OutputAdapter(template="{{ value }}", output_type=tuple[Literal["["], int])
restored = OutputAdapter.from_dict(adapter.to_dict())
# Before: DeserializationError: Could not import 'typing.Literal['['], int'
# After: restored.output_type == adapter.output_type

The same problem affects Literal["]|"], nested Callable and Optional types, and PEP 604 unions containing these values.

  • Make the two existing delimiter scanners respect quoted strings and escaped quotes/backslashes before counting brackets or splitting commas/pipes
  • Preserve previously accepted triple-quoted strings in direct deserialize_type() inputs
  • Add focused type round-trip regressions, direct triple-quote compatibility tests, and two OutputAdapter.to_dict()/from_dict() regressions
  • Add a Reno release note

The serialized format and deserialization allowlist are unchanged.

How did you test it?

Locally with Python 3.12.14 and Hatch 1.14.2:

  • On unchanged main, the existing type-serialization and OutputAdapter suites passed: 217 passed
  • Adding the initial 16 regression cases without the production fix produced 15 failed, 1 passed
  • After the fix and six triple-quote compatibility cases, the related serialization/component suites passed: 538 passed
hatch run test:unit \
  test/utils/test_type_serialization.py \
  test/utils/test_callable_serialization.py \
  test/utils/test_base_serialization.py \
  test/core/test_serialization.py \
  test/core/test_serialization_security.py \
  test/components/converters/test_output_adapter.py \
  test/components/routers/test_conditional_router.py --no-cov

Also passed:

  • hatch run fmt-check across the repository
  • hatch run test:types across all 550 source files
  • hatch run pre-commit run --files for the four changed files
  • hatch run reno lint . and the release-note backtick check
  • git diff --check
  • An additional local exhaustive check of 28,086 string/bytes/nested/union round trips, including bracket, quote, backslash, comma and pipe combinations

The full unit suite, live integrations, Docker-based license-header CI job, and other Python versions were not run locally. No provider credentials or model downloads were used.

Notes for the reviewer

This PR was fully generated with an AI assistant. AI was used for the investigation, implementation, testing, independent review, and this write-up. The reported checks were run locally. The independent review identified the triple-quoted input compatibility case, which is covered by the added tests.

Checklist

@vercel

vercel Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

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

A member of the Team first needs to authorize it.

@CLAassistant

CLAassistant commented Oct 1, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@hulkbig
hulkbig marked this pull request as ready for review October 3, 2026 12:50
@hulkbig
hulkbig requested a review from a team as a code owner October 3, 2026 12:50
@hulkbig
hulkbig requested review from sjrl and removed request for a team October 3, 2026 12:50

This branch has not been deployed

No deployments
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.

2 participants