resilient-context-extraction
What it does
This skill tells the AI agent to read any files you attach and treat them as the main source of facts. It is for people who give the AI reference files to work from.
When to use it
- ✓When you attach a spreadsheet, PDF or data file and ask the AI to build something from it.
- ✓When the AI's answer seems to ignore the file you gave it.
- ✓When reading a file looks incomplete and you want the AI to try other ways to open it.
Skill link
https://github.com/HKUDS/AgentPilot/blob/main/openspace/benchmarks/gdpval/skills/prioritize-context-data-enhanced/SKILL.mdCopy 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
For Claude Code, Codex or Cursor: run it in your project folder and the skill gets installed.
Download the SKILL.md and drop it into your agent’s skills folder.
Example of what to ask your AI
“Use the numbers in the attached sales file for my report, and do not search the web for them.”
5 new skills a week. 1 minute to read.
How it works
The agent lists every file you provided, checks which ones match the task, and reads them before looking anywhere else. If a read looks incomplete, it tries another method.
Technical content (original SKILL.md)
Original text by the author, straight from GitHub.
Resilient Context Extraction
Objective
Prevent data hallucination and inefficiency by mandating that agents inspect, validate, and fully extract data from provided reference files before attempting web searches or generating synthetic data. When extraction is incomplete, use fallback strategies before making assumptions.
Critical Rule
If a reference file is provided in the task context, it is the source of truth. Do not fabricate data or search the web for information that may exist within the provided attachments. If extraction appears incomplete, attempt alternative methods before proceeding.
Workflow Steps
1. Scan Context for Attachments
At the start of every task, explicitly list all files provided in the context window or attachment panel.
- Check for spreadsheets (
.xlsx,.csv), documents (.pdf,.docx,.pptx), or data dumps (.json,.txt,.xml,.yaml). - Note the filename, file size (if available), and inferred content type.
- Record this list for later verification.
2. Evaluate Relevance
Determine if any provided file contains the data required to complete the task.
- Match Keywords: Do filenames or expected column headers match task requirements?
- Check Scope: Does the data cover the necessary timeframe or region?
- Prioritize: Rank files by likelihood of containing required data.
3. Extract Data with Validation
If relevant files are found:
- Read the file content using appropriate tools (e.g.,
read_file,pandas,pdf_reader). - Validate Extraction Completeness (NEW CRITICAL STEP):
- Check if output appears truncated (e.g., sudden cutoff mid-sentence, character limits hit).
- Compare expected data points vs. extracted data points (e.g., "Task mentions pricing tiers; did extraction include pricing numbers?").
- Look for structural indicators of incompleteness (e.g., unclosed tables, missing document endings).
- If extraction is incomplete or suspicious, proceed to Step 4 (Fallback Strategies) before using the data.
4. Apply Fallback Extraction Strategies
When initial extraction is incomplete or critical data is missing, attempt these strategies in order before making assumptions:
4a. Alternative Library/Tool Approach
- For
.docx: Trypython-docxdirectly viaexecute_code_sandboxifread_filewas truncated. - For
.xlsx/.csv: Trypandaswith explicit sheet selection oropenpyxldirectly. - For
.pdf: Trypdfplumber,PyPDF2, or shell-basedpdftotextif available. - For any format: Try reading as raw bytes/text via shell commands (
cat,xxd,strings).
4b. Shell-Based Extraction
- Use
shell_agentorrun_shellfor format-specific tools:unzip -p file.docx word/document.xml | xmllint --format -(extract raw docx XML)in2csv file.xlsx(convert Excel to CSV via shell)pdftotext file.pdf -(extract PDF text via command line)
- This bypasses potential sandbox or library limitations in
read_file.
4c. Targeted Re-Reading
- If specific sections are missing (e.g., "pricing table on page 3"), attempt to re-read with focus on that region.
- Use tools that support page/section ranges if available.
4d. Document What's Missing
- Before any assumptions or external searches, explicitly document:
- What data was expected but not found.
- What extraction methods were attempted.
- Why each method failed or what portions remain unavailable.
- Example: "Attempted
read_fileonPricing_email.docx(truncated at 980 chars). Attemptedpython-docxextraction via sandbox—pricing table in section 2 not present in file. Pricing numbers unavailable from provided context."
5. Cite Source Explicitly
When presenting data in the final output:
- Explicitly state which file the data came from.
- Example: "According to
Massabama_active_listings.xlsx..." - If fallback methods were used, note this: "Extracted via shell-based
pdftotextfromreport.pdf..." - This verifies to the user that real data was used, not hallucinated.
6. Fallback to Search (Last Resort Only)
If all extraction strategies fail to provide the specific data needed:
- State clearly what was missing from the files.
- Document all extraction methods attempted and why they failed.
- Then proceed with web search or estimation.
- Mark any non-file data clearly as "External Search" or "Estimated (file data unavailable)".
- Never present estimated data as if it came from the file.
Che
FAQ
Will the agent still search the web if a fact is missing from my file?
The skill asks the agent to confirm the file really lacks the fact first. Only then should it look elsewhere.
Which file types does this skill cover?
It names spreadsheets, PDFs, Word files, CSV, JSON and text files as the kinds of files to check.
What if the agent still ignores my file?
Ask it to list the files it can see and to read the one you need before it continues.
Details
Original description by the author
Ensures agents extract data from context files with validation and fallback strategies before resorting to assumptions or external searches.
repo: HKUDS/AgentPilot
Popularity
- GitHub stars
- 7.8k
- Ranking position
- #12951
- License
- MIT
- Updated
- 11/1/2026
Comments
- …
More skills from this repository
agentpilot
7.8kHelps your agent improve a project step by step by preparing a task and running the AgentPilot loop that proposes, tests and scores changes.
openspace
7.8kHelps your agent set up OpenSpace, a tool that stores and fetches agent skills, and connect it to your AI app through MCP.
rsi-arena
7.8kHelps your agent set up and run standard AI benchmark tests, such as AIME and Terminal-Bench, to compare different improvement methods.
experiment-guide
7.8kHelps your agent plan small experiments, read their results and record findings while it investigates how to improve a program.
Similar skills
add-model-provider
394kLets your agent connect a new AI model provider to OpenClaw using safe setup commands, keep API keys out of plain text, and run a live test.
acp-router
394kHelps your agent send a task to a coding assistant such as Claude Code or Cursor through OpenClaw, so the work runs in that tool.
browser-automation
394kTeaches your agent to control web pages step by step, including logins, tabs, and recovery when a page stops responding.