Unified document generation with tool failure detection, domain knowledge fallback, progressive conversion, and Unicode safety
Use this workflow when generating documents in challenging environments where:
read_file, search_web, read_webpage, or execute_code_sandbox return errors.docx, .pdf, .html from the same sourceThis skill combines early failure detection, domain-knowledge content creation, progressive conversion fallbacks, and Unicode safety into a single resilient workflow.
┌─────────────────────────────────────────────────────────────────┐
│ 1. DETECT tool failures (2+ indicators → pivot immediately) │
└────────────────┬────────────────────────────────────────────────┘
│
┌────────────────▼────────────────────────────────────────────────┐
│ 2. CREATE content with write_file using embedded domain │
│ knowledge (professionally structured markdown) │
└────────────────┬────────────────────────────────────────────────┘
│
┌────────────────▼────────────────────────────────────────────────┐
│ 3. SANITIZE unicode (create LaTeX-safe version for PDF) │
└────────────────┬────────────────────────────────────────────────┘
│
┌────────────────▼────────────────────────────────────────────────┐
│ 4. CONVERT with progressive fallbacks: │
│ pandoc → reportlab → fpdf2 → wkhtmltopdf │
└────────────────┬────────────────────────────────────────────────┘
│
┌────────────────▼────────────────────────────────────────────────┐
│ 5. VERIFY outputs exist and are valid │
└─────────────────────────────────────────────────────────────────┘
Before attempting document generation, check for failure indicators:
TOOL_FAILURE_INDICATORS = [
"read_file returns binary/image data instead of text",
"search_web returns unknown error or empty results",
"read_webpage returns unknown error on multiple URLs",
"execute_code_sandbox fails unexpectedly",
"pandoc command fails with 'unknown error'",
"Multiple consecutive tool failures on data retrieval"
]
Decision point: If 2+ indicators are present within the first 2-3 iterations:
Write your document as professionally structured Markdown using embedded domain knowledge:
write_file