{"record":{"id":"c1a5a68f3972dc2b","repo":"huggingface/smolagents","slug":"unknown-final-answer-format-expected-safe-or","errorCode":null,"errorMessage":"Unknown final answer format: expected 'safe:' or 'pickle:' prefix","messagePattern":"Unknown final answer format: expected 'safe:' or 'pickle:' prefix","errorType":"validation","errorClass":"SerializationError","httpStatus":null,"severity":"error","filePath":"src/smolagents/remote_executors.py","lineNumber":332,"sourceCode":"        Args:\n            encoded_value (`str`): Serialized string from FinalAnswerException.\n            allow_pickle (`bool`, default `False`): Whether to allow pickle deserialization.\n\n        Returns:\n            `Any`: Deserialized Python object.\n\n        Raises:\n            SerializationError: If pickle data is rejected.\n        \"\"\"\n        if encoded_value.startswith(\"safe:\"):\n            json_data = json.loads(encoded_value[5:])\n            return SafeSerializer.from_json_safe(json_data)\n        elif encoded_value.startswith(\"pickle:\"):\n            if not allow_pickle:\n                raise SerializationError(\"Pickle data rejected: allow_pickle=False\")\n            return pickle.loads(base64.b64decode(encoded_value[7:]))\n        else:\n            raise SerializationError(\"Unknown final answer format: expected 'safe:' or 'pickle:' prefix\")\n\n\nclass E2BExecutor(RemotePythonExecutor):\n    \"\"\"\n    Remote Python code executor in an E2B sandbox.\n\n    Args:\n        additional_imports (`list[str]`): Additional Python packages to install.\n        logger (`Logger`): Logger to use for output and errors.\n        allow_pickle (`bool`, default `False`): Whether to allow pickle serialization for objects that cannot be safely serialized to JSON.\n            - `False` (default, recommended): Only safe JSON serialization is used. Raises error if object cannot be safely serialized.\n            - `True` (legacy mode): Tries safe JSON serialization first, falls back to pickle with warning if needed.\n\n            **Security Warning:** Pickle deserialization can execute arbitrary code. Only set `allow_pickle=True`\n            if you fully trust the execution environment and need backward compatibility with custom types.\n        **kwargs: Additional keyword arguments to pass to the E2B Sandbox instantiation.\n    \"\"\"\n","sourceCodeStart":314,"sourceCodeEnd":350,"githubUrl":"https://github.com/huggingface/smolagents/blob/30bb1161095dbae2271e6bc3cc4c219cc3897a57/src/smolagents/remote_executors.py#L314-L350","documentation":"SerializationError raised when the encoded final answer string does not start with 'safe:' or 'pickle:'. The deserializer cannot determine the format, so it fails closed rather than guessing.","triggerScenarios":"A FinalAnswerException payload reaching _deserialize_final_answer whose evalue is raw JSON, plain text, or was produced by a different smolagents version with another prefix scheme.","commonSituations":"Version mismatch between the package running inside the sandbox and the host; manual/crafted exceptions carrying arbitrary strings; user code raising exceptions whose message collides with the final-answer mechanism.","solutions":["Ensure the same smolagents version runs on host and inside the sandbox/Docker image (rebuild the image)","Don't raise FinalAnswerException-like errors manually with arbitrary payloads","Upgrade both sides to a current version, then retry"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"def has_known_prefix(encoded: str) -> bool:\n    return encoded.startswith(\"safe:\") or encoded.startswith(\"pickle:\")","typeGuard":null,"tryCatchPattern":"from smolagents.remote_executors import SerializationError\n\ntry:\n    value = RemotePythonExecutor._deserialize_final_answer(encoded, allow_pickle)\nexcept SerializationError as e:\n    if \"prefix\" in str(e):\n        # version mismatch between sandbox and host\n        rebuild_or_reinstall_sandbox_env()\n    raise","preventionTips":["Pin identical smolagents versions on host and sandbox","Rebuild Docker images after upgrading smolagents","Don't craft final-answer exception messages manually"],"tags":["deserialization","final-answer","format-prefix","version-mismatch"],"backgroundTag":"payload-format-unrecognized","analyzedSha":"30bb1161095dbae2271e6bc3cc4c219cc3897a57","analyzedAt":"2026-08-28T18:52:54.169Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}