diff --git a/MIGRATION.md b/MIGRATION.md index af75d498fc..dce8a569b2 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -73,6 +73,26 @@ from haystack.dataclasses import Document doc = Document(content="col\n1\n2\n3") ``` +### `GeneratedAnswer` and `ExtractedAnswer` serialization format + +**What changed:** `GeneratedAnswer.to_dict()` and `ExtractedAnswer.to_dict()` now return a flat dictionary of the object's fields instead of wrapping them in a `{"type": ..., "init_parameters": {...}}` envelope. `from_dict()` still accepts the old wrapped format, so existing serialized artifacts keep loading. + +**Why:** Aligns these dataclasses with how every other Haystack dataclass (`Document`, `ChatMessage`, etc.) serializes, and removes redundant type metadata from pipeline snapshots and `State` objects. + +**How to migrate:** Update any code that reads the serialized output to access fields at the top level instead of under `init_parameters`. See [#11805](https://github.com/deepset-ai/haystack/pull/11805). + +Before (v2.x): +```python +serialized = generated_answer.to_dict() +data = serialized["init_parameters"]["data"] +``` + +After (v3.0): +```python +serialized = generated_answer.to_dict() +data = serialized["data"] +``` + ### Components Moved to External Packages **What changed:** Some components have been moved out of Haystack into dedicated integration packages, diff --git a/releasenotes/notes/fix-dataclasses-deseria-0bb839b5edd3fca6.yaml b/releasenotes/notes/fix-dataclasses-deseria-0bb839b5edd3fca6.yaml new file mode 100644 index 0000000000..567cca034d --- /dev/null +++ b/releasenotes/notes/fix-dataclasses-deseria-0bb839b5edd3fca6.yaml @@ -0,0 +1,10 @@ +--- +upgrade: + - | + ``GeneratedAnswer`` and ``ExtractedAnswer`` now serialize to the same flat format as + all other Haystack dataclasses (``Document``, ``ChatMessage``, etc.). This is a breaking + change: ``to_dict()`` no longer wraps the fields in the ``{"type": "...", "init_parameters": + {...}}`` envelope and instead returns the fields at the top level. Any code or stored + artifact that reads the serialized output and expects the ``type``/``init_parameters`` + keys must be updated to read the fields directly. ``from_dict()`` remains backward + compatible and still accepts the old wrapped format.