{"record":{"id":"37794198bfbce752","repo":"deepset-ai/haystack","slug":"outputs-to-string-raw-result-must-be-a-boolean","errorCode":null,"errorMessage":"outputs_to_string raw_result must be a boolean.","messagePattern":"outputs_to_string raw_result must be a boolean\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"haystack/tools/tool.py","lineNumber":164,"sourceCode":"\n            # Validate that outputs_to_state source keys exist as valid tool outputs\n            valid_outputs: set[str] | None = self._get_valid_outputs()\n            if valid_outputs is not None:\n                for state_key, config in self.outputs_to_state.items():\n                    source = config.get(\"source\")\n                    if source is not None and source not in valid_outputs:\n                        raise ValueError(\n                            f\"outputs_to_state: '{self.name}' maps state key '{state_key}' to unknown output '{source}'\"\n                            f\"Valid outputs are: {valid_outputs}.\"\n                        )\n\n        if self.outputs_to_string is not None:\n            if \"source\" in self.outputs_to_string and not isinstance(self.outputs_to_string[\"source\"], str):\n                raise ValueError(\"outputs_to_string source must be a string.\")\n            if \"handler\" in self.outputs_to_string and not callable(self.outputs_to_string[\"handler\"]):\n                raise ValueError(\"outputs_to_string handler must be callable\")\n            if \"raw_result\" in self.outputs_to_string and not isinstance(self.outputs_to_string[\"raw_result\"], bool):\n                raise ValueError(\"outputs_to_string raw_result must be a boolean.\")\n\n            if (\n                \"source\" in self.outputs_to_string\n                or \"handler\" in self.outputs_to_string\n                or \"raw_result\" in self.outputs_to_string\n            ):\n                # Single output configuration\n                for key in self.outputs_to_string:\n                    if key not in {\"source\", \"handler\", \"raw_result\"}:\n                        raise ValueError(\n                            \"Invalid outputs_to_string config. \"\n                            \"When using 'source', 'handler' or 'raw_result' at the root level, no other keys are \"\n                            \" allowed. Use individual output configs instead.\"\n                        )\n            else:\n                # Multiple outputs configuration\n                for key, config in self.outputs_to_string.items():\n                    if not isinstance(config, dict):","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/deepset-ai/haystack/blob/e318778c9bf60a1963e3b5f451359655dd696c30/haystack/tools/tool.py#L146-L182","documentation":"A root-level \"raw_result\" in outputs_to_string controls whether the raw tool result (vs. the serialized string) is used, and must be a bool. __post_init__ raises ValueError for non-boolean values like strings \"true\"/\"false\" or ints 0/1.","triggerScenarios":"Tool(..., outputs_to_string={\"raw_result\": \"true\"}) or {\"raw_result\": 1} — truthy non-bool values from env/config parsing.","commonSituations":"Configs sourced from environment variables or YAML/JSON where booleans are parsed as strings; hand-built dicts using 0/1.","solutions":["Pass a real boolean: {\"raw_result\": True} or False.","If the value comes from a config string, coerce with `str(v).lower() == \"true\"` or `bool(v)` (carefully) before constructing the Tool.","Remove \"raw_result\" if the default behavior is desired."],"exampleFix":"// before\nraw = os.getenv(\"TOOL_RAW_RESULT\", \"false\")\noutputs_to_string={\"raw_result\": raw}\n\n// after\nraw = os.getenv(\"TOOL_RAW_RESULT\", \"false\").lower() == \"true\"\noutputs_to_string={\"raw_result\": raw}","handlingStrategy":"type-guard","validationCode":"ots = outputs_to_string or {}\nif \"raw_result\" in ots and not isinstance(ots[\"raw_result\"], bool):\n    raise TypeError(\"raw_result must be a bool\")","typeGuard":"def valid_raw_result(ots: dict | None) -> bool:\n    v = (ots or {}).get(\"raw_result\", True)\n    return isinstance(v, bool)","tryCatchPattern":"try:\n    tool = Tool(name=\"t\", function=f, outputs_to_string=ots)\nexcept ValueError as e:\n    if \"raw_result must be a boolean\" in str(e):\n        logger.error(f\"Coerce raw_result to bool: {e}\")\n    raise","preventionTips":["Coerce env/config strings with `v.lower() == \"true\"` before passing","Never use 0/1 or \"true\"/\"false\" strings for boolean options","Add type checks when loading tool configs from YAML/JSON"],"tags":["python","tool","config","type-error"],"backgroundTag":"invalid-config-shape","analyzedSha":"e318778c9bf60a1963e3b5f451359655dd696c30","analyzedAt":"2026-08-30T11:45:20.711Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}