diff --git a/lib/crewai/pyproject.toml b/lib/crewai/pyproject.toml index a5f96fb277..ea1c1e772e 100644 --- a/lib/crewai/pyproject.toml +++ b/lib/crewai/pyproject.toml @@ -32,7 +32,7 @@ dependencies = [ "click>=8.1.7,<9", "appdirs~=1.4.4", "jsonref~=1.1.0", - "json-repair~=0.25.2", + "json-repair>=0.60.1,<1.0", "cel-python>=0.5.0,<0.6", "tomli-w~=1.1.0", "tomli~=2.0.2", diff --git a/lib/crewai/src/crewai/agents/parser.py b/lib/crewai/src/crewai/agents/parser.py index c59719226c..e680d779ee 100644 --- a/lib/crewai/src/crewai/agents/parser.py +++ b/lib/crewai/src/crewai/agents/parser.py @@ -6,6 +6,7 @@ """ from dataclasses import dataclass +import json from json_repair import repair_json # type: ignore[import-untyped] from pydantic import BaseModel @@ -176,4 +177,15 @@ def _safe_repair_json(tool_input: str) -> str: if result in UNABLE_TO_REPAIR_JSON_RESULTS: return tool_input + # json-repair >=0.60 fabricates output (e.g. wraps non-JSON text in a + # list) instead of returning an empty sentinel, so a non-empty result no + # longer means the input was valid JSON. Only trust a result that parses + # back to a JSON object; otherwise keep the original string. + try: + parsed = json.loads(result) + except json.JSONDecodeError: + return tool_input + if not isinstance(parsed, dict): + return tool_input + return str(result)