fix: append traceback to tool execution error messages#6265
Conversation
Closes crewAIInc#6262 Tool exceptions were caught and replaced with generic error strings like 'Error executing tool: {e}', discarding the original traceback and making debugging impossible. Fixed by appending traceback.format_exc(limit=5) to all tool execution error returns across 4 files: - agents/crew_agent_executor.py: main tool execution handler - experimental/agent_executor.py: 4 exception handlers including printer output and action.result - utilities/agent_utils.py: native tool call handler - llm.py: LLMCallFailedEvent and ToolUsageErrorEvent The 'Error executing tool:' prefix is preserved to avoid breaking existing parsing logic. traceback.format_exc(limit=5) limits output to 5 frames to avoid flooding LLM context windows. Pre-existing test failures (RuntimeError: Network is disabled) confirmed unrelated via git stash verification on Windows Python 3.13 with pytest-recording.
There was a problem hiding this comment.
Summary: This PR adds traceback details to tool execution error messages and related telemetry/error propagation paths.
Risk: Low risk. No exploitable security vulnerabilities were identified; the added tracebacks expose diagnostic context but do not create a realistic attacker-controlled privilege, data access, injection, or execution path in the reviewed changes.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughFour files import ChangesTool Exception Traceback Enrichment
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Hi! Addressing the CodeRabbit inconclusive check. We intentionally chose appending traceback strings
This PR addresses the core debuggability problem from #6262 Happy to add the structured format if maintainers prefer that |
Closes #6262
Problem
When a tool raised an exception, CrewAI caught it and
returned a generic string like "Error executing tool: {e}",
discarding the original traceback. This made debugging
impossible — users couldn't tell if the failure was a
network error, validation error, rate limit, or tool bug.
Fix
Appended
traceback.format_exc(limit=5)to all toolexecution error returns across 4 files:
agents/crew_agent_executor.py— main tool execution handlerexperimental/agent_executor.py— 4 exception handlersincluding printer output and
action.resultutilities/agent_utils.py— native tool call handlerllm.py—LLMCallFailedEventandToolUsageErrorEventDesign Decisions
"Error executing tool:"prefix preserved — avoidsbreaking existing parsing logic
limit=5chosen to balance debuggability vs LLMcontext window consumption
of error string before the traceback
Testing
Pre-existing test failures (
RuntimeError: Network is disabled) confirmed unrelated to this change viagit stashverification on Windows Python 3.13with pytest-recording.
Summary by CodeRabbit