Diagnose and resolve a Python runtime error, traceback, or unexpected behavior
by systematically isolating the root cause and applying the minimal fix.
Approach
Read the full traceback from bottom to top — identify the exception type and line
Reproduce the error in isolation with a minimal test case
Check for common causes: import errors, type mismatches, concurrency issues
Inspect the call stack for unexpected state mutations
Apply the minimal fix and verify with the original failing case
Add a regression test to prevent recurrence
Tools used
pdb: interactive debugger for stepping through execution
pytest: run targeted test to reproduce and verify fix
traceback: format and analyze exception chains
Known constraints
Always reproduce before fixing — never guess-fix
Prefer minimal changes over refactoring during debugging
Document the root cause in the commit message
Known failure modes
Fixing the symptom instead of the root cause (e.g., catching an exception instead of preventing it)
Using fork start method on macOS (use spawn instead for multiprocessing)
Missing transitive dependency errors masked by dev environment
Circular import issues hidden by lazy imports
Examples
Good output pattern
Root cause:Pool.map() hangs on macOS because the default start method is fork, which is unsafe with threads.
Fix: Set mp.set_start_method("spawn") before creating the pool.
Regression test: Added test_pool_spawn_method() to verify spawn is used.
Bad output pattern
"I added a try/except around the error so it doesn't crash anymore."
1---2name: debug-python-error3description: Debug Python Error4---5# Debug Python Error67## When to use this skill8Diagnose and resolve a Python runtime error, traceback, or unexpected behavior9by systematically isolating the root cause and applying the minimal fix.1011## Approach121. Read the full traceback from bottom to top — identify the exception type and line132. Reproduce the error in isolation with a minimal test case143. Check for common causes: import errors, type mismatches, concurrency issues154. Inspect the call stack for unexpected state mutations165. Apply the minimal fix and verify with the original failing case176. Add a regression test to prevent recurrence1819## Tools used20- pdb: interactive debugger for stepping through execution21- pytest: run targeted test to reproduce and verify fix22- traceback: format and analyze exception chains2324## Known constraints25- Always reproduce before fixing — never guess-fix26- Prefer minimal changes over refactoring during debugging27- Document the root cause in the commit message2829## Known failure modes30- Fixing the symptom instead of the root cause (e.g., catching an exception instead of preventing it)31- Using fork start method on macOS (use spawn instead for multiprocessing)32- Missing transitive dependency errors masked by dev environment33- Circular import issues hidden by lazy imports3435## Examples36### Good output pattern37**Root cause:** `Pool.map()` hangs on macOS because the default start method is `fork`, which is unsafe with threads.38**Fix:** Set `mp.set_start_method("spawn")` before creating the pool.39**Regression test:** Added `test_pool_spawn_method()` to verify spawn is used.4041### Bad output pattern42"I added a try/except around the error so it doesn't crash anymore."
Run npx skillmds@latest add siddhu1716/debug-python-error in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
Debug Python Error It is listed under Coding & Dev Tools on SkillMD.
This skill has not completed SkillMD's automated safety review yet. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
siddhu1716 (@siddhu1716) published this skill. Their other Agent Skills are listed on their SkillMD profile.