Skip to content
Skillpedia
PDF, Word & slides7.8k · #12927

pdf-gen-fallback-dee20c

What it does

This skill is a PDF generation fallback with library checks and visible error handling. It is for people whose PDF or report jobs fail in the sandbox without a clear reason.

When to use it

  • ✓When the sandbox gives unclear errors while I am creating a PDF or report.
  • ✓When I want error messages shown so I can see what went wrong.
  • ✓When I need a simple PDF saved as a file on this computer.

Skill link

https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/pdf-gen-fallback-dee20c/SKILL.md

Copy 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

Use this skill to help me: https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/pdf-gen-fallback-dee20c/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
Want your AI to find skills like this on its own?Install the free Skillpedia MCP: one line, and it searches 15,000+ skills before each task.Install in 1 minute →

Example of what to ask your AI

“Create a simple PDF with my title and text. The sandbox fails with no clear message, so run it from the shell and show me any errors.”

5 new skills a week. 1 minute to read.

How it works

The AI checks the needed libraries, then runs a Python script from the shell that writes the PDF and prints a success message, with the code wrapped in error handling.

Technical content (original SKILL.md)

Original text by the author, straight from GitHub.

PDF Generation Fallback Workflow

Purpose

When execute_code_sandbox returns opaque or unhelpful errors during document/PDF generation, use run_shell with direct python -c execution as a reliable alternative. This pattern includes library availability checks and explicit error handling.

When to Use

  • execute_code_sandbox fails with unclear error messages during document generation
  • PDF, report, or document creation tasks are failing unexpectedly
  • You need more control over the Python execution environment

Step-by-Step Instructions

1. Check Library Availability

Before attempting generation, verify required libraries are installed:

run_shell: python -c "import reportlab; print('reportlab OK')"
run_shell: python -c "import fpdf; print('fpdf OK')"
run_shell: python -c "import PyPDF2; print('PyPDF2 OK')"

If a library is missing, install it:

run_shell: pip install reportlab --quiet

2. Execute Generation via run_shell

Instead of execute_code_sandbox, use run_shell with python -c:

run_shell: python -c "
from reportlab.lib.pagesizes import letter
from reportlab.pdfgen import canvas
c = canvas.Canvas('output.pdf', pagesize=letter)
c.drawString(100, 750, 'Document Content')
c.save()
print('PDF generated successfully')
"

3. Handle Errors Explicitly

Wrap generation code with try/except and capture stderr:

run_shell: python -c "
import sys
try:
    # Your generation code here
    from reportlab.pdfgen import canvas
    c = canvas.Canvas('output.pdf')
    c.drawString(100, 750, 'Content')
    c.save()
    print('SUCCESS: PDF created')
    sys.exit(0)
except Exception as e:
    print(f'ERROR: {type(e).__name__}: {e}', file=sys.stderr)
    sys.exit(1)
" 2>&1

4. Verify Output File

After generation, confirm the file was created:

run_shell: ls -la output.pdf
run_shell: file output.pdf

5. Fallback Hierarchy

If the first approach fails, try alternatives in this order:

  1. reportlab - Full-featured PDF generation
  2. fpdf - Simpler PDF library
  3. wkhtmltopdf - HTML to PDF conversion
  4. Direct text/Markdown output as last resort

Example: Complete Workflow

# Step 1: Check library
run_shell: python -c "import reportlab; print('OK')"

# Step 2: Generate with error handling
run_shell: python -c "
import sys
try:
    from reportlab.lib.pagesizes import letter
    from reportlab.pdfgen import canvas
    c = canvas.Canvas('report.pdf', pagesize=letter)
    c.setTitle('Surveillance Report')
    c.drawString(100, 750, 'Revised Surveillance Report')
    c.drawString(100, 730, 'Summary: Key findings documented')
    c.save()
    print('SUCCESS')
except Exception as e:
    print(f'FAILED: {e}', file=sys.stderr)
    sys.exit(1)
"

# Step 3: Verify
run_shell: test -f report.pdf && echo 'File exists' || echo 'File missing'

Troubleshooting

Issue Solution
Module not found pip install <module> --quiet
Permission denied Check output directory permissions
Font errors Use default fonts or install font packages
Encoding issues Specify encoding explicitly in string operations

Best Practices

  • Always capture both stdout and stderr for debugging
  • Exit with proper status codes (0 for success, 1 for failure)
  • Keep generation code concise when using python -c
  • For complex generation, write a temporary .py file instead
  • Test library availability before attempting generation
FAQ

Why wrap the code in error handling?

The guide says it makes failures show clearly instead of being hidden.

What does the script print at the end?

A success message, so the result is easy to confirm.

Which library does the example use?

The example uses reportlab's canvas to draw text and save the PDF.

Details

Original description by the author

Fallback workflow for document generation when code sandbox returns opaque errors

repo: HKUDS/AgentPilot

Popularity

GitHub stars
7.8k
Ranking position
#12927
License
MIT
Updated
11/1/2026

Is this skill useful?

0

Sign in to vote.

Comments

  • …

More skills from this repository

Similar skills