# Pitfalls Index — Canonical Query Templates > **Match-and-fuse, don't read-and-think.** Each entry below is a > production-ready prompt template. When the user's incoming query > matches a `Match signatures` block, **copy the matching canonical > query**, substitute the `Slots` with the user's actual values, > and execute it verbatim. Each canonical query already encodes every > known pitfall, every verification gate, and every fall-back path > for that scenario — there is no extra "trace" to look up. > > If no signature matches, fall back to [`../SKILL.md`](../SKILL.md) routing. > If a partial match (one of two slots fits), prefer **fusing** the > matching template's verifications into your own plan rather than > writing a new one from scratch. > > **Universal slot placeholders below** — these are referenced inside > every canonical query and resolve at execution time: > > - `` → `{{DATA_DIR}}/.builtin-skills/pdf` > - `` → `{{DATA_DIR}}/.builtin-skills/xlsx` > - `` → a writable scratch dir (e.g. `/tmp/pdf-task-`) --- ## Quick lookup — match user query to a case | # | Match keywords | Slots | Canonical §| |---|---|---|---| | **P1** | brand guide / cover / poster / 品牌指南 / 设计规范 from a website | `BRAND_URL`, `OUTPUT_PATH`, `BRAND_NAME`, `PAGE_COUNT(default 2)`, `AUDIENCE(intl/US)` | §P1 | | **P2** | bilingual menu / 双语菜单 / formal printed deliverable / certificate / two-pager | `LANG_A`, `LANG_B`, `RESTAURANT_TYPE`, `ITEMS_JSON`, `OUTPUT_PATH`, `AUDIENCE` | §P2 | | **P3** | markdown→PDF / convert structured text to chart-rich PDF / 可视化报告 / data brief | `INPUT_PATH(.md/.csv)`, `OUTPUT_PATH`, `CHART_COUNT`, `THEME(default light)` | §P3 | | **P4** | research report across N jurisdictions / multi-region regulatory survey / 多国监管 | `TOPIC`, `JURISDICTIONS[]`, `OUTPUT_PDF`, `DEADLINE_MIN(default 30)` | §P4 | | **P5** | translate this to preserving layout / 翻译保版 | `INPUT_PATH(.eml/.pdf)`, `TARGET_LANG`, `OUTPUT_PATH` | §P5 | | **P6** | find in this <100+ page PDF> / 长 PDF 定向提取 / extract specific data from annual report | `PDF_PATH`, `TARGET_QUERY`, `MAX_OUTPUT_PAGES(optional)` | §P6 | | **P7** | convert <240-page financial PDF> to Excel/Word/Markdown / 复杂金融排版 PDF 转格式 | `PDF_PATH`, `OUTPUT_FORMAT`, `OUTPUT_PATH`, `STATEMENTS[]` | §P7 | | **P8** | fill out this PDF form / AcroForm / visa / tax / contract / 表单填写 | `FORM_PDF`, `MATERIALS[]`, `OUTPUT_PDF`, `MISSING_FIELDS_REPORT(true)` | §P8 | | **P9** | export 10k+ row spreadsheet as PDF / 大表打印 / tabular → PDF | `INPUT_XLSX`, `OUTPUT_PDF`, `ORIENTATION`, `REPEAT_HEADER`, `FULL_OR_PREVIEW` | §P9 | | **P10** | convert to with fidelity loss report / 双向转换 | `INPUT_PATH`, `TARGET_FORMATS[]`, `OUTPUT_DIR` | §P10 | --- ## P1 — Branded paged PDF from web content ### Match signatures - "做一份 {BRAND_NAME}({BRAND_URL})的 brand guide / 品牌指南 PDF" - "make a brand-guide / cover / poster PDF from {BRAND_URL}" - "把 {site} 抓取的品牌元素整理成双页 PDF" - "create a 2-page design system overview for {company}" ### Canonical query ``` TASK: Generate a {PAGE_COUNT}-page brand guide PDF for {BRAND_NAME} from {BRAND_URL}, output to {OUTPUT_PATH}. STEP 1 — Environment preflight (mandatory) bash /scripts/make.sh check 2>/check.log # WARN/FAIL → bash /scripts/make.sh fix && re-run check STEP 2 — Brand asset extraction (precise, not inferred) curl -sL "{BRAND_URL}" > /brand.html 2>/curl.log # Palette — exact hex from CSS/SVG (NEVER infer from prose) grep -oE '#[0-9a-fA-F]{6}' /brand.html | sort -u > /palette.txt grep -oP 'fill="\K#[0-9a-fA-F]{6}' /brand.html | sort -u >> /palette.txt # Fonts grep -oiE 'font-family[: ][^;}"]+' /brand.html | sort -u # Logo — download SVG / PNG separately # If points off-domain, fetch each one and grep colors there too. STEP 3 — Template + fill placeholders cp /templates/brand-guide-2page/skeleton.html /page.html # Replace tokens with: # - {BRAND_NAME}, tagline (LLM-extracted from site if user didn't supply) # - 6-color palette from /palette.txt (top 6 unique hex) # - Font stack from grep above # - Logo as or file:// reference STEP 4 — Render (mandatory --format) bash /scripts/make.sh render \ --in /page.html --out {OUTPUT_PATH} \ --format --wait 15000 # Never rely on the renderer default; Chromium overrides CSS @page. STEP 5 — Verification (BOTH gates mandatory) pdfinfo {OUTPUT_PATH} | grep "Page size" # Must print: 595.276 x 841.89 pts (A4) OR 612 x 792 pts (Letter) # Mismatch → go back to STEP 4, do not ship. pdfimages -list {OUTPUT_PATH} | tail -n +3 | wc -l # Must be ≥ 1 (logo); typically ≥ 6 (logo + palette swatches + samples). # If 0 → Chart.js / fonts didn't settle. Bump --wait 30000, set # Chart.defaults.animation = false, wrap canvases in .avoid-break. STEP 6 — Deliver with evidence Report: pdfinfo "Page size" line + pdfimages count + screenshot of page 1. CONSTRAINTS (universal — do not violate): - NEVER `2>/dev/null` — redirect to /*.log and grep on demand. - Palette MUST come from CSS/SVG hex, never from rendered prose ("looks blue-ish"). - Always pass --format explicitly to make.sh render. ``` --- ## P2 — Bilingual menu / formal printed two-pager ### Match signatures - "做一份 {LANG_A}-{LANG_B} 双语 {RESTAURANT_TYPE} 菜单 PDF" - "make a {LANG_A}/{LANG_B} bilingual menu / wine list / certificate" - "design a 2-page formal printed PDF for {use_case}" ### Canonical query ``` TASK: Render a 2-page bilingual ({LANG_A} + {LANG_B}) {RESTAURANT_TYPE} menu PDF from items in {ITEMS_JSON}, output to {OUTPUT_PATH}. STEP 1 — Preflight bash /scripts/make.sh check 2>/check.log STEP 2 — Use the canonical template (do not author from scratch) cp /templates/bilingual-menu-premium/skeleton.html /menu.html # Inject ITEMS_JSON: each item has {LANG_A_name, LANG_B_name, price, category} # Categories ≥ 3 (e.g. 前菜/Sushi/甘味). Pricing follows pricing_model. STEP 3 — CJK font cascade verification # If LANG_A or LANG_B ∈ {zh, ja, ko}, the HTML MUST declare: # font-family: -apple-system, "PingFang SC", "Hiragino Sans", # "Apple SD Gothic Neo", "Helvetica Neue", sans-serif; # Cascade ORDER MATTERS — wrong order renders SC chars in JP forms. STEP 4 — Render (canonical CLI shape) bash /scripts/make.sh render \ --in /menu.html --out {OUTPUT_PATH} \ --format A4 --wait 15000 # The flag is `--in` (not --input), `--out` (not --output). # A4 by default for CJK / international audiences. STEP 5 — Verification (CJK-aware) pdfinfo {OUTPUT_PATH} | grep "Page size" # 595x841 pts (A4) pdfimages -list {OUTPUT_PATH} | tail -n +3 | wc -l pdftotext -layout {OUTPUT_PATH} - | head -40 # Look for [ ] [ ] tofu boxes in the CJK output. If any → install # missing CJK font (`brew install font-noto-sans-cjk-sc`), re-render. STEP 6 — Spot-check first page visually (optional but recommended) pdftoppm -r 150 -png -f 1 -l 1 {OUTPUT_PATH} /preview # Open /preview-1.png to confirm typography & balance. CONSTRAINTS: - Memorize the canonical render CLI shape: --in / --out (NOT --input / --output). - For CJK languages, verify font cascade ORDER, not just presence. - --format defaults to A4 here because menus are international/CJK; for US-only steakhouses pass --format Letter explicitly. ``` --- ## P3 — Markdown / structured text → chart-rich PDF ### Match signatures - "把 {INPUT_PATH} (markdown/csv) 转成含图表的 PDF 报告" - "convert this benchmark / dataset / md into a visualized PDF" - "make a data brief from {INPUT_PATH}" - "可视化报告 / 图文报告 / 评测报告 / data report" ### Canonical query ``` TASK: Build a chart-rich PDF report from {INPUT_PATH}, with approximately {CHART_COUNT} charts (auto-estimate if unspecified), output to {OUTPUT_PATH}. STEP 1 — Preflight bash /scripts/make.sh check 2>/check.log # Includes Playwright Chromium check; fix if WARN. STEP 2 — Choose template cp -r /templates/data-viz-report/* / # The skeleton.html has KPI grid, chart-card, takeaway-row, conclusion primitives. # If acceptance criteria require source hierarchy preservation, print-academic style, # and static charts only (no Chart.js/ECharts/D3/Plotly), load: # /docs/markdown-static-academic-data-viz-case.md # and follow that case instead of the Chart.js skeleton path. STEP 3 — Build content.json (mandatory ensure_ascii=False) python3 </content.json").write_text( json.dumps(payload, ensure_ascii=False, indent=2), encoding="utf-8", ) EOF # NEVER hand-concatenate JSON strings. CJK quotes / em-dashes break json.load. STEP 4 — Render (mandatory --format + long --wait for charts) bash /scripts/make.sh render \ --in /page.html --out {OUTPUT_PATH} \ --format A4 --wait 15000 # 15s baseline; if charts are non-trivial (>30 series, animated), use 25000. STEP 5 — Verification (both gates mandatory; pdftotext alone is NOT enough) pdfinfo {OUTPUT_PATH} | grep "Page size" IMG_COUNT=$(pdfimages -list {OUTPUT_PATH} | tail -n +3 | wc -l) echo "Image count: $IMG_COUNT (expected ≥ {CHART_COUNT})" # IMG_COUNT < CHART_COUNT → at least one chart is a blank canvas. pdftotext -layout {OUTPUT_PATH} - | head -40 # body text sanity STEP 6 — Chart-rendering recovery (when STEP 5 image count is low) # 1. In the source HTML's