deepset-ai/haystack · critical · DeserializationError

Refusing to deserialize an OutputAdapter with unsafe=True wh

Error message

Refusing to deserialize an OutputAdapter with unsafe=True while loading in safe mode. If you trust the source of this data, load it with Pipeline.load(..., unsafe=True).

What it means

OutputAdapter.from_dict refuses to restore a serialized component whose init_parameters contain unsafe=True when the pipeline is being loaded in safe mode. unsafe=True swaps the Jinja sandbox for a NativeEnvironment that can execute arbitrary code, so honoring it from data alone would let a hostile pipeline YAML/JSON escape the sandbox.

Source

Thrown at haystack/components/converters/output_adapter.py:180

        )

    @classmethod
    def from_dict(cls, data: dict[str, Any]) -> "OutputAdapter":
        """
        Deserializes the component from a dictionary.

        :param data:
            The dictionary to deserialize from.
        :returns:
            The deserialized component.
        """
        init_params = data.get("init_parameters", {})

        # `unsafe=True` swaps the Jinja sandbox for a NativeEnvironment that executes arbitrary code.
        # Honor it from serialized data only when the whole pipeline is being loaded in unsafe mode;
        # otherwise a hostile pipeline could disable the sandbox on its own in default safe mode.
        if init_params.get("unsafe") and not _is_unsafe_deserialization():
            raise DeserializationError(
                "Refusing to deserialize an OutputAdapter with unsafe=True while loading in safe mode. "
                "If you trust the source of this data, load it with Pipeline.load(..., unsafe=True)."
            )

        custom_filters = init_params.get("custom_filters", {})
        if custom_filters and not _is_unsafe_deserialization():
            raise DeserializationError(
                "Refusing to deserialize an OutputAdapter with custom filters while loading in safe mode. "
                "Custom filters are arbitrary callables that can execute during pipeline loading. "
                "If you trust the source of this data, load it with Pipeline.load(..., unsafe=True)."
            )

        init_params["output_type"] = deserialize_type(init_params["output_type"])

        if custom_filters:
            init_params["custom_filters"] = {
                name: deserialize_callable(filter_func) if filter_func else None
                for name, filter_func in custom_filters.items()

View on GitHub (pinned to e318778c9b)

Solutions

  1. If you trust the file's source, load with Pipeline.loads(data, unsafe=True)
  2. Re-save the pipeline with OutputAdapter(unsafe=False) and verify the template still works in the sandbox
  3. Remove unsafe=True from the serialized init_parameters if the template doesn't need it

Example fix

// before
pipeline = Pipeline.loads(data)
// after
pipeline = Pipeline.loads(data, unsafe=True)  # only if you trust this pipeline's source
Defensive patterns

Strategy: try-catch

Validate before calling

import yaml
def uses_unsafe_adapter(path):
    data = yaml.safe_load(open(path))
    return any(
        c.get("type") == "OutputAdapter" and c.get("init_parameters", {}).get("unsafe")
        for c in data.get("components", []).values()
    )

Try / catch

try:
    pipeline = Pipeline.load(path)
except DeserializationError as e:
    if "unsafe=True" in str(e) and is_trusted_source(path):
        pipeline = Pipeline.load(path, unsafe=True)
    else:
        raise

Prevention

When it happens

Trigger: Pipeline.load(path) (default safe mode) on a pipeline file saved with OutputAdapter(unsafe=True); loading untrusted third-party pipeline definitions containing unsafe:true in the OutputAdapter's init_parameters.

Common situations: Downloading shared pipeline recipes from the internet; upgrading Haystack where serialized pipelines exported with unsafe=True now get rejected at load; CI loading stored pipeline artifacts.

Related errors


AI-assisted analysis of deepset-ai/haystack@e318778c9b (2026-08-30). Data as JSON: /api/errors/b16afd5d7dd21c5f. Report an issue: GitHub.