Repository: confident-ai/deepeval
Issue: CallbackHandler crashes with boolean outputs from LangChain tools/LangGraph
Root cause: Validation Gap

**Describe the bug**
The DeepEval LangChain CallbackHandler fails when tracing tools or LangGraph workflows that return boolean values. The error occurs because DeepEval Cloud expects string/object/array types in span outputs, but receives boolean primitives, causing schema validation failures.

**To Reproduce**
 1. Install dependencies: pip install deepeval langgraph langchain-core python-dotenv
 2. Set your DeepEval API key: export CONFIDENT_AI_API_KEY=your_key
 3. Run this minimal reproduction: https://gist.github.com/anatolyburtsev/68f67971b94f04c8c7d9a846c05e0439
 4. See the error:

```
[Confident AI Trace Log]  Flushing 1 remaining trace(s)
[Confident AI Trace Log]  Error flushing remaining trace(s): [
  {
    "code": "invalid_union",
    "unionErrors": [
      {
        "issues": [
          {
            "code": "invalid_type",
            "expected": "string",
            "received": "boolean",
            "path": [
              "toolSpans",
              0,
              "output"
            ],
            "message": "Expected string, received boolean"
          }
        ],
        "name": "ZodError"
      },
      {
        "issues": [
          {
            "code": "invalid_type",
            "expected": "object",
            "received": "boolean",
            "path": [
              "toolSpans",
              0,
              "output"
            ],
            "message": "Expected object, received boolean"
          }
        ],
        "name": "ZodError"
      },
      {
        "issues": [
          {
            "code": "invalid_type",
            "expected": "array",
            "received": "boolean",
            "path": [
              "toolSpans",
              0,
              "output"
            ],
            "message": "Expected array, received boolean"
          }
        ],
        "name": "ZodError"
      }
    ],
    "path": [
      "toolSpans",
      0,
      "output"
    ],
    "message": "Invalid input"
  }
]
```

The issue occurs when any LangChain tool returns a boolean value while using DeepEval's CallbackHandler for tracing.

**Expected behavior**
The tool should execute successfully and traces should be sent to DeepEval Cloud without schema validation errors. Boolean outputs should be automatically handled/converted to a compatible format.


**Desktop (please complete the following information):**
 - OS: [e.g. iOS] Mac OS 15.5

**Libraries:**
- deepeval: 3.3.2
- langgraph: 0.2.61

**Additional context**
Root Cause: The bug is in the [CallbackHandler's on_tool_end() method](https://github.com/confident-ai/deepeval/blob/main/deepeval/integrations/langchain/callback.py#L310)  where tool_span.output = output directly assigns boolean values without sanitization.


  Proposed fix: Add output sanitization in the CallbackHandler:
 ```
def _sanitize_output(output):
      if isinstance(output, bool):
          return str(output)
      # handle other non-serializable types...
      return output

  # Apply in on_tool_end():
  tool_span.output = _sanitize_output(output)
```


Hey @anatolyburtsev should be fixed now, can you try again?

Issue has been resolved, Thanks!