{"record":{"id":"72018bc6de92c232","repo":"langchain-ai/deepagents","slug":"stream-output-is-visible-must-be-a-bool-got-type","errorCode":null,"errorMessage":"stream_output_is_visible must be a bool, got {type(stream_output_is_visible).__name__}","messagePattern":"stream_output_is_visible must be a bool, got (.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"libs/code/deepagents_code/model_retry.py","lineNumber":1076,"sourceCode":"        Raises:\n            TypeError: If `max_retries` or `stream_output_is_visible` has the\n                wrong type.\n            ValueError: If `max_retries` is negative.\n        \"\"\"\n        # `True >= 0` passes and `range(True + 1)` runs two attempts, so an\n        # unchecked bool reads as a budget of one retry.\n        if isinstance(max_retries, bool):\n            msg = f\"max_retries must be an int, got {type(max_retries).__name__}\"\n            raise TypeError(msg)\n        if max_retries < 0:\n            msg = \"max_retries must be >= 0\"\n            raise ValueError(msg)\n        if not isinstance(stream_output_is_visible, bool):\n            msg = (\n                \"stream_output_is_visible must be a bool, got \"\n                f\"{type(stream_output_is_visible).__name__}\"\n            )\n            raise TypeError(msg)\n        self.max_retries = max_retries\n        self.stream_output_is_visible = stream_output_is_visible\n\n    @staticmethod\n    def _emit_stream_event(request: ModelRequest, event: dict[str, object]) -> None:\n        writer = getattr(getattr(request, \"runtime\", None), \"stream_writer\", None)\n        if writer is None:\n            return\n        try:\n            writer(event)\n        except GraphBubbleUp:\n            # LangGraph control flow must not be mistaken for a writer fault.\n            raise\n        except Exception:\n            # These events are the only signal that a pause is a retry and the\n            # only correlation a client has between chunks and attempts, so\n            # losing one must be visible in the logs without failing the run.\n            logger.warning(","sourceCodeStart":1058,"sourceCodeEnd":1094,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/code/deepagents_code/model_retry.py#L1058-L1094","documentation":"The constructor validates that `stream_output_is_visible` is strictly a `bool`. Passing any other type (int, string, None) raises a `TypeError` naming the received type, so stream visibility can never be truthiness-inferred.","triggerScenarios":"Passing `stream_output_is_visible=1`, `\"yes\"`, `None`, or a config value that was not converted to bool when constructing the retry model.","commonSituations":"Environment variables parsed as strings (`STREAM_VISIBLE=\"1\"`) passed through unconverted; JSON configs with 0/1 or \"true\"/\"false\" strings; forwarding an Optional value without a default.","solutions":["Pass an explicit boolean: `stream_output_is_visible=True`","Coerce at the config boundary with `bool(int(os.environ.get(...)))` or `value in (\"1\", \"true\")`","Give Optional values an explicit boolean default before construction"],"exampleFix":"// before\nRetryModel(inner, stream_output_is_visible=os.environ.get(\"STREAM_VISIBLE\"))\n// after\nRetryModel(inner, stream_output_is_visible=os.environ.get(\"STREAM_VISIBLE\", \"1\") == \"1\")","handlingStrategy":"type-guard","validationCode":"if not isinstance(stream_output_is_visible, bool):\n    raise TypeError(f\"stream_output_is_visible must be bool, got {type(stream_output_is_visible).__name__}\")","typeGuard":"def is_bool(v: object) -> TypeGuard[bool]:\n    return isinstance(v, bool)","tryCatchPattern":"try:\n    model = RetryModel(inner, stream_output_is_visible=flag)\nexcept TypeError as e:\n    logging.error(\"bad flag type: %s\", e)\n    model = RetryModel(inner, stream_output_is_visible=False)","preventionTips":["Convert env vars and config strings to bool at the boundary","Avoid Optional[bool] without an explicit default","Enable type checkers to catch non-bool arguments"],"tags":["python","validation","type-error","streaming"],"backgroundTag":"invalid-parameter-type","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}