Generate professional documents using write_file when primary data sources fail, leveraging embedded domain knowledge instead of external retrieval
复制下面这句话,粘贴给 Claude Code、Codex、Cursor 等 AI 编程工具,它会读取安装说明并在你确认后完成安装。
请阅读 https://ai.atlankj.com/install/asset/gh-write-file-fallback-report-06401cb49dd7 ,按照其中的说明把「write-file-fallback-report」安装到你(当前 AI 工具)中。执行前先告诉我将运行的命令和写入的位置,等我确认。
查看 AI 将读取的安装说明正在读取 GitHub 原文…
内容来自 GitHub 原始文件,由原作者维护。在 GitHub 查看
Use this workflow when attempting to generate a document or report, but multiple primary data source tools fail simultaneously:
read_file returns binary/image data instead of text (common with PDFs)search_web returns errors or no resultsexecute_code_sandbox fails unexpectedlyKey insight: Rather than getting stuck on failed data retrieval, pivot immediately to generating the document directly with write_file using professionally structured content and embedded domain knowledge.
Recognize when you're in a fallback scenario:
TOOL_FAILURE_INDICATORS = [
"read_file returns binary or image data",
"search_web returns unknown error or empty results",
"execute_code_sandbox fails repeatedly",
"Multiple consecutive tool failures on data retrieval"
]
Decision point: If 2+ indicators are present, proceed to Step 2.
Stop attempting to fix the failing tools. Instead:
write_file as your primary tool (not a last resort)Create a well-organized markdown document with:
# [Document Title]
## Executive Summary
[Brief overview of key findings/content]
## Background
[Context and scope - use embedded knowledge]
## Main Content
[Organized sections with headers, lists, tables as appropriate]
## Limitations & Notes
[Transparent about data source limitations if relevant]
## Recommendations/Next Steps
[Actionable guidance based on available information]
When external data is unavailable:
Example:
> **Note**: Specific [metric/data point] would typically be sourced from
> [expected source]. The guidance below reflects established best practices
> in this domain.
# Example execution pattern
write_file(
path="output/report.md",
content=professionally_structured_markdown
)
# Verify the file was created successfully
list_dir(path=".") # Confirm file exists
# Detection and pivot pattern
def detect_and_pivot(task_goal):
# After detecting tool failures:
report_content = f"""# {task_goal} Report
## Executive Summary
This report was generated using established domain knowledge due to
temporary unavailability of primary data sources.
## Key Frameworks and Guidance
[Structured content with headers, bullets, tables]
## Limitations
- Specific data points from [expected sources] were unavailable
- Recommendations based on general best practices
## Action Items
1. [Concrete step 1]
2. [Concrete step 2]
"""
write_file(path="generated_report.md", content=report_content)
return "Report generated successfully with embedded knowledge"
| Do | Don't |
|---|---|
| Pivot quickly after 2+ tool failures | Keep retrying failing tools 5+ times |
| Be transparent about limitations | Claim unverified specifics as facts |
| Provide actionable frameworks | Leave the task incomplete |
| Use professional document structure | Output unstructured text walls |
| Include next-step recommendations | End without clear guidance |
The skill is successfully applied when: