{"record":{"id":"6c2e55a6c58c2332","repo":"tensorflow/models","slug":"is-treatment-must-be-a-tensor-castable-to-boolean","errorCode":null,"errorMessage":"is_treatment must be a tensor castable to boolean but got tensor {is_treatment} of dtype {is_treatment.dtype} instead.","messagePattern":"is_treatment must be a tensor castable to boolean but got tensor (.+?) of dtype (.+?) instead\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/recommendation/uplift/utils.py","lineNumber":68,"sourceCode":"    A tuple with control and treatment values sliced by the is_treatment tensor.\n  \"\"\"\n  if is_treatment.shape.rank > 2 or (\n      is_treatment.shape == 2 and is_treatment.shape[1] != 1  # pyrefly: ignore[unsupported-operation]\n  ):\n    raise ValueError(\n        \"is_treatment tensor must be a tensor of shape (D0,) (D0, 1) but got a\"\n        f\" tensor of shape {is_treatment.shape} instead.\"\n    )\n\n  if values.shape[0] != is_treatment.shape[0]:\n    raise ValueError(\n        \"values and is_treatment must be tensors of shapes (D0, D1, ..., DN)\"\n        f\" and (D0, 1) (or (D0,)), but got tensors of shapes {values.shape} and\"\n        f\" {is_treatment.shape} respectively.\"\n    )\n\n  if is_treatment.dtype == tf.string:\n    raise ValueError(\n        \"is_treatment must be a tensor castable to boolean but got tensor\"\n        f\" {is_treatment} of dtype {is_treatment.dtype} instead.\"\n    )\n\n  # Assert is_treatment tensor containss only 0 or 1 values.\n  if is_treatment.dtype != tf.bool:\n    is_treatment_float = tf.cast(is_treatment, tf.float32)\n    tf.debugging.assert_equal(\n        tf.reduce_all(\n            tf.logical_or(is_treatment_float == 1.0, is_treatment_float == 0.0)\n        ),\n        tf.convert_to_tensor(True),\n        message=(\n            \"When is_treatment is not a boolean tensor all of its values must\"\n            f\" either be 0 or 1, but got tensor {is_treatment} instead.\"\n        ),\n    )\n","sourceCodeStart":50,"sourceCodeEnd":86,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/recommendation/uplift/utils.py#L50-L86","documentation":"Error \"is_treatment must be a tensor castable to boolean but got tensor {is_treatment} of dtype {is_treatment.dtype} instead.\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/recommendation/uplift/utils.py:68 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e006f5f0d534913e49c1f1dae87364039fa607e2","analyzedAt":"2026-08-24T14:09:15.576Z","schemaVersion":2},"datasetVersion":"2026-08-24T17:17:21.512Z"}