Skip to content

feat: Add support to deserialize chat messages serialized with pydantic - #12025

Merged
sjrl merged 1 commit into
mainfrom
improve-chat-message-deser
Jul 16, 2026
Merged

feat: Add support to deserialize chat messages serialized with pydantic#12025
sjrl merged 1 commit into
mainfrom
improve-chat-message-deser

Conversation

@sjrl

@sjrl sjrl commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Related Issues

  • fixes #issue-number

Proposed Changes:

When a ChatMessage is a field of a Pydantic model (e.g. an API request/response DTO), model_dump() silently serializes it as a plain dataclass: raw fields (_role, _content) with content parts unwrapped ({"tool_name": ..., "arguments": ...} instead of {"tool_call": {...}}). ChatMessage.from_dict rejected this format for anything containing tool calls, tool results, reasoning, images, and files.

This was causing issues in platform because they couldn't easily deserialize incoming ChatMessages using ChatMessage.from_dict before passing it off to the Haystack pipeline. So ChatMessage.from_dict now also accepts the Pydantic auto-serialized format to help make it easier in platform to deserialize ChatMessages.

How did you test it?

Added new tests.

Notes for the reviewer

cc @tstadel

Checklist

  • I have read the contributors guidelines and the code of conduct.
  • I have updated the related issue with new insights and changes.
  • I have added unit tests and updated the docstrings.
  • I've used one of the conventional commit types for my PR title: fix:, feat:, build:, chore:, ci:, docs:, style:, refactor:, perf:, test: and added ! in case the PR includes breaking changes.
  • I have documented my code.
  • I have added a release note file, following the contributors guidelines.
  • I have run pre-commit hooks and fixed any issue.

@vercel

vercel Bot commented Jul 16, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
haystack-docs Ignored Ignored Jul 16, 2026 6:02am

Request Review

@github-actions github-actions Bot added topic:tests type:documentation Improvements on the docs labels Jul 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  haystack/dataclasses
  chat_message.py
Project Total  

This report was generated by python-coverage-comment-action

@sjrl sjrl self-assigned this Jul 16, 2026
@sjrl
sjrl marked this pull request as ready for review July 16, 2026 06:12
@sjrl
sjrl requested a review from a team as a code owner July 16, 2026 06:12
@sjrl
sjrl requested review from anakin87 and bogdankostic and removed request for a team and bogdankostic July 16, 2026 06:12

@anakin87 anakin87 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok for me

@sjrl
sjrl merged commit 64fb0d2 into main Jul 16, 2026
30 checks passed
@sjrl
sjrl deleted the improve-chat-message-deser branch July 16, 2026 07:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic:tests type:documentation Improvements on the docs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants