Skip to content

docs: detailing in docstrings the scope and context of each serialisation function#11903

Merged
davidsbatista merged 2 commits into
v3from
docs/clarify-serialization-envelope-boundaries-v3
Jul 7, 2026
Merged

docs: detailing in docstrings the scope and context of each serialisation function#11903
davidsbatista merged 2 commits into
v3from
docs/clarify-serialization-envelope-boundaries-v3

Conversation

@davidsbatista

Copy link
Copy Markdown
Contributor

Related Issues

Proposed Changes:

Docstring-only additions, no behavior change. Added short "why" notes to 5 functions that looked like they could be merged or simplified, but can't:

  • default_to_dict/default_from_dict (core/serialization.py) — notes this is the on-disk pipeline YAML format, incompatible with base_serialization's.
  • _serialize_value_with_schema (utils/base_serialization.py) — notes it's for runtime values, not Components, and points back to the note above.
  • _serializable_value (tracing/utils.py) — notes it's deliberately one-way/lossy, unlike the schema serializer.
  • _serialize_content_part (dataclasses/chat_message.py) — notes the short tags are a deliberate hand-writable public format.
  • _serialize_object (components/generators/utils.py) — notes it skips private attributes for OpenAI SDK objects, unlike the generic serializer.

These came out of an investigation into duplicated/scattered serialization code (see related PRs). Most of what looked like duplication turned out to be intentional separation — these notes capture the reasoning directly in the code so it doesn't get
"helpfully" merged later.

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.

@davidsbatista davidsbatista requested a review from a team as a code owner July 7, 2026 14:52
@davidsbatista davidsbatista requested review from anakin87 and removed request for a team July 7, 2026 14:52
@vercel

vercel Bot commented Jul 7, 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 Preview Jul 7, 2026 3:51pm

Request Review

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

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  haystack/components/generators
  utils.py
Project Total  

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

@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.

I left some questions and comments

Comment thread haystack/components/generators/utils.py Outdated
Convert an object to a serializable dict recursively.

Used for OpenAI SDK response objects, so it skips any attribute starting with "_" (SDK-internal
fields). `base_serialization`'s serializer doesn't skip those, so don't swap this out for it.

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.

base_serialization's serializer

Which function in this file? Let's specify this.

I am also realizing that serialize_class_instance in base_serialization is not used. Right?

Comment thread haystack/components/generators/utils.py Outdated
"""
Convert an object to a serializable dict recursively.

Used for OpenAI SDK response objects, so it skips any attribute starting with "_" (SDK-internal

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.

If I am not wrong it's only used for logprobs serialization. Maybe it's worth specifying this. WDYT?

Comment thread haystack/core/serialization.py Outdated

This is the format used for saved pipeline files (`Pipeline.dump`/`Pipeline.load`). Don't merge
it with `base_serialization`'s serializer — that one uses a different envelope for a different
job (arbitrary runtime values, not Components) and changing either would break saved files.

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.

Which function in base_serialization?

Comment thread haystack/dataclasses/chat_message.py Outdated

Output looks like `{"text": "hello"}` or `{"image": {...}}` — short, hand-writable keys, not a
full class name. People write these by hand (e.g. in chat templates), so keep it this way.

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.

This docstring addition does not seem particularly helpful. I'd also delete it, because it already seems clear that this function is very specific to the ChatMessage content part.

Comment thread haystack/core/serialization.py Outdated
This is mostly necessary for components but can be used by any object. Reverses the
`{"type": ..., "init_parameters": ...}` envelope produced by `default_to_dict` — see that
function's docstring for why this envelope is not interchangeable with
`haystack.utils.base_serialization`'s.

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.

Which function in base_serialization?

@claude

claude Bot commented Jul 7, 2026

Copy link
Copy Markdown

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

@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.

Looks good.

Keep in mind to remove unused functions from base_serialization (in another PR).

@davidsbatista

Copy link
Copy Markdown
Contributor Author

@anakin87 #11905

@davidsbatista davidsbatista enabled auto-merge (squash) July 7, 2026 16:00
@davidsbatista davidsbatista merged commit 2bcb65f into v3 Jul 7, 2026
25 checks passed
@davidsbatista davidsbatista deleted the docs/clarify-serialization-envelope-boundaries-v3 branch July 7, 2026 16:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic:core type:documentation Improvements on the docs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants