python-debug-pattern
What it does
This skill gives the AI agent a repeatable way to run Python scripts and find out why they fail. It is for anyone who needs clear error details from a script.
When to use it
- ✓When a Python script fails and you only see an opaque message.
- ✓When a script writes to a file and you need to confirm where it went.
- ✓When you want the AI to compare a good run with a bad run.
Skill link
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/python-debug-pattern/SKILL.mdCopy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.
How to use
The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.
Ready-to-paste message
For Claude Code, Codex or Cursor: run it in your project folder and the skill gets installed.
Download the SKILL.md and drop it into your agent’s skills folder.
Example of what to ask your AI
“Run my process_data script and tell me exactly why it fails, including the full error.”
5 new skills a week. 1 minute to read.
How it works
The agent runs the script with stderr captured and prints the exit code. It logs the working directory and the absolute path of any file the script writes to.
Technical content (original SKILL.md)
Original text by the author, straight from GitHub.
Python Debug Pattern
This skill provides a reusable pattern for debugging Python script execution failures. It ensures you capture actual tracebacks instead of opaque errors and verify the working directory before file operations.
Core Technique
1. Execute Python Scripts with Full Error Capture
When running Python scripts, always use this command pattern to surface actual tracebacks:
python3 script.py 2>&1 ; echo Exit code: $?
Why this works:
2>&1redirects stderr to stdout, capturing both regular output and errors; echo Exit code: $?displays the actual exit code after execution- This reveals the full Python traceback instead of opaque failure messages
Examples:
# Good: Full error capture
python3 process_data.py 2>&1 ; echo Exit code: $?
# Bad: Opaque error (no stderr capture, no exit code)
python3 process_data.py
2. Verify Working Directory Before File Operations
Before any file read/write operations in Python, verify the current working directory:
import os
# At script start, log the working directory
print(f"Working directory: {os.getcwd()}")
# For file operations, use absolute paths or log the resolved path
file_path = "output/result.csv"
abs_path = os.path.abspath(file_path)
print(f"Writing to: {abs_path}")
Why this works:
- Many failures occur because scripts run from unexpected directories
- Logging the working directory immediately surfaces path-related issues
- Absolute paths prevent ambiguity in file operations
Full example script structure:
#!/usr/bin/env python3
import os
import sys
def main():
# Debug: verify working directory
print(f"Working directory: {os.getcwd()}", file=sys.stderr)
# Debug: list directory contents if dealing with files
print(f"Directory contents: {os.listdir('.')}", file=sys.stderr)
# Your actual logic here
# ...
if __name__ == "__main__":
main()
When to Apply This Pattern
- Python script fails with an opaque error message
- File operations (read/write) fail unexpectedly
- Script works locally but fails in automated execution
- Debugging CI/CD pipeline failures
- Investigating "file not found" or permission errors
Quick Checklist
- Run script with
2>&1 ; echo Exit code: $?pattern - Add
os.getcwd()logging at script start - Use
os.path.abspath()for file paths - Log directory contents with
os.listdir('.')if relevant - Check for missing dependencies (capture full traceback)
Common Failure Modes This Pattern Surfaces
| Symptom | Without Pattern | With Pattern |
|---|---|---|
| File not found | "Error: failed" | Full traceback showing exact path attempted |
| Permission denied | Script exits silently | stderr shows permission error |
| Missing module | Opaque exit | ImportError with module name |
| Wrong directory | Confusing path errors | cwd logged, reveals directory mismatch |
FAQ
What is a traceback?
A traceback is the list of steps Python took before an error, and it shows where the problem happened.
Why log the absolute path of an output file?
It shows exactly where the file was saved, which helps when you cannot find it.
Can I use this without editing my script?
Yes, the run command alone shows the errors, though the diagnostic lines help more.
Details
Original description by the author
Debug Python script execution failures by capturing full output with exit codes and verifying working directory before file operations
repo: HKUDS/AgentPilot
Popularity
- GitHub stars
- 7.8k
- Ranking position
- #12957
- License
- MIT
- Updated
- 11/1/2026
Comments
- …
More skills from this repository
agentpilot
7.8kHelps your agent improve a project step by step by preparing a task and running the AgentPilot loop that proposes, tests and scores changes.
openspace
7.8kHelps your agent set up OpenSpace, a tool that stores and fetches agent skills, and connect it to your AI app through MCP.
rsi-arena
7.8kHelps your agent set up and run standard AI benchmark tests, such as AIME and Terminal-Bench, to compare different improvement methods.
experiment-guide
7.8kHelps your agent plan small experiments, read their results and record findings while it investigates how to improve a program.
Similar skills
diffs
394kLets your agent produce a real, shareable diff of edits as a viewer link or image file, instead of a hand-written summary.
coding-agent
394kHelps your agent hand a larger coding job to Codex, Claude Code, or OpenCode as a background worker, then check on its progress.
gh-issues
394kHelps your agent find GitHub issues, pick the ones to work on, and open pull requests with fixes, including follow-up on review comments.