Emergency Disposal Card Generator (应急处置卡生成器)
Enterprise tool for automatically extracting emergency scenarios from safety documents and generating standardized emergency disposal cards conforming to GB/T 29639-2020 and industry best practices.
Overview
This skill transforms unstructured safety documentation into structured, actionable emergency disposal cards. Each card contains:
- Scenario identification and risk classification
- Pre-incident preventive measures
- Step-by-step emergency response procedures
- Personnel roles and contact escalation
- Required emergency equipment and supplies
- Post-incident recovery guidance
Workflow
Phase 1: Load and Parse Input
- Accept input as:
- Plain text pasted by the user
.pdffiles.docxfiles (use python-docx to extract).txtor.mdfiles- Multiple documents for batch processing
- Extract text with the following priority:
- MinerU first for PDF: prefer MinerU-generated markdown/text when available
- Fallback to PyPDF2 / fitz / pdfplumber / pdfminer / OCR
- Clean before chunking:
- Remove page numbers, empty noise lines, duplicate short fragments, control characters, and layout residue
- Normalize whitespace and paragraph boundaries
- Split long documents into chunks after cleaning
- Identify emergency scenarios present in the document or chunk
Phase 2: Read Reference Materials
Before generating cards, read the following reference files in order:
- prompt.md — System prompt template for the LLM
- schema.json — Output JSON Schema for card validation
- examples/output.json — Reference output example
Phase 3: Generate Cards via LLM
Use the following approach to generate cards:
- For short documents: Compose the full
prompt.mdwith the cleaned text and call the LLM - For long documents: Chunk only after cleaning; run one LLM pass per cleaned chunk
- For batch generation: For each scenario identified, generate a card separately or merge chunk-level results
- Aggregation: Merge duplicate scenario cards across chunks instead of simply dropping duplicates
- Validation: Validate each card output against
schema.json
LLM Call Configuration
Recommended model parameters:
- Model: qwen-plus or gpt-4o (or user's available model)
- Temperature: 0.1 (for consistency)
- Streaming: false
- Response format: JSON object
Prompt Assembly
system_prompt = read_file("prompt.md")
cleaned_text = clean_document_text(extracted_text)
chunks = split_text_into_chunks(cleaned_text)
human_prompt = f"""请根据以下【源文档内容】生成应急处置卡。
【源文档内容】:
{chunks[0]}
严格按照 schema.json 定义的 JSON Schema 格式返回。直接输出 JSON,不要包含任何 Markdown 标记。"""
Phase 4: Post-process and Deliver
- Parse LLM JSON response
- Validate against schema.json
- Present cards to user in readable format (markdown tables or formatted cards)
- Optionally export as
.docx(requested by user)
Quality Standards
- Strict source grounding: Every procedure, hazard, and measure must be traceable to the source document
- Zero hallucination: Do not invent procedures, chemical names, or safety protocols not present in the source
- Completeness: Each card should have all fields populated; if source lacks information, mark as "源文档未提供" (not provided in source)
Batch Processing
For large documents containing multiple scenarios:
- First pass: extract raw text
- Clean text before any chunking
- Split the cleaned text into chunks
- Generate chunk-level cards
- Merge duplicate scenarios across chunks
- Combine into a single output array
Example
See examples/output.json for a complete reference output.
Bundled Resources
Scripts (scripts/)
generate_cards.py— Standalone CLI tool for batch generating emergency disposal cards from text documents.- Usage:
python scripts/generate_cards.py --input <document.txt> --output <cards.json> - Supports configurable model, temperature, API key, chunk size, and chunk overlap
- Supports MinerU-first PDF ingestion through
MINERU_MARKDOWN_PATH, sibling MinerU markdown files, orMINERU_CMD - Reads
prompt.mdfor system prompt
- Usage:
Examples (examples/)
input.docx— Sample safety document excerpt (chemical spill + fall from height)input.txt— Same content in plain text for quick testingoutput.json— Generated cards for the sample input, for reference validation
Scan to join WeChat group