Sci-Data-Extractor
Extract structured data from scientific literature PDFs using AI-powered OCR and LLM analysis. Supports enzyme kinetics, experimental results, and literature review templates. Use when researchers need to parse tables, charts, or text from paper PDFs into Markdown or CSV. Triggers: extract data from PDF, scientific data extraction, parse paper tables, enzyme kinetics extraction, batch PDF extraction, literature data, research data from paper, OCR scientific paper, convert PDF to structured data.
npx skills add github:pantheon-org/tekhne --skill documentation--research--sci-data-extractorAI-powered tool for extracting structured data from scientific literature PDFs. Converts tables, figures, and text from research papers into Markdown tables or CSV files using PyMuPDF (free) or Mathpix OCR (high-precision) plus an LLM extraction layer.
When to Use
- Extracting enzyme kinetics parameters (Km, Kcat, Kcat/Km) from biochemistry papers
- Converting experimental result tables from PDFs to structured CSV or Markdown
- Building a literature review dataset from multiple paper PDFs
- Batch-processing a folder of PDFs into a unified dataset
- Parsing complex tables or chart data points that require AI assistance
When Not to Use
- The paper is already in a machine-readable format (XML, JSON, HTML) — parse it directly
- You only need the abstract or title — use
semantic-scholar-searchinstead - The PDF is scanned at low resolution with no embedded text and Mathpix is unavailable — results will be unreliable
- You need real-time citation counts or DOI resolution — use
semantic-scholar-search
Mindset
Data extraction from PDFs is a pipeline with multiple failure points — always validate each stage.
- OCR first, extraction second: a gotcha is assuming PyMuPDF handles all PDFs equally. Scanned images, complex multi-column layouts, and formula-heavy pages are a known pitfall — switch to Mathpix for high-precision needs or pre-inspect output before running AI extraction.
- Prompts determine quality: the AI extraction layer is only as good as the extraction prompt. ALWAYS review the raw LLM output before saving; consider that ambiguous column headers or merged table cells can silently corrupt extracted values.
- Batch is not atomic: a production gotcha is treating batch runs as pass/fail. ALWAYS check the per-file success log; failed files are listed at the end and must optionally be re-run individually.
Workflow
1. Install dependencies (first run only)
See setup-and-troubleshooting.md.
2. Configure environment variables
export EXTRACTOR_API_KEY="your-api-key-here"
export EXTRACTOR_BASE_URL="https://api.anthropic.com"
export EXTRACTOR_MODEL="claude-sonnet-4-5-20250929"
# Optionally for Mathpix OCR:
export MATHPIX_APP_ID="your-mathpix-app-id"
export MATHPIX_APP_KEY="your-mathpix-app-key"
3. Run with a preset template
# Enzyme kinetics data — extracts Km, Kcat, organism, mutant, etc.
./scripts/extractor.py paper.pdf --template enzyme -o results.md
# Experimental results — extracts conditions, values, p-values, sample size
./scripts/extractor.py paper.pdf --template experiment -o results.md
# Literature review — extracts authors, year, DOI, key findings
./scripts/extractor.py paper.pdf --template review -o references.md
4. Run with a custom prompt
./scripts/extractor.py paper.pdf \
-p "Extract all protein structure data: PDB ID, resolution, R-value, R_free" \
-o custom.md
5. Output as CSV
./scripts/extractor.py paper.pdf --template enzyme -o results.csv --format csv
6. Use Mathpix OCR for high-precision extraction
./scripts/extractor.py paper.pdf --template enzyme -o results.md --ocr mathpix
7. Batch-process a folder of PDFs
./scripts/batch_extract.py ./literature/ ./output/ --template enzyme --format csv
8. Print extracted results to terminal
./scripts/extractor.py paper.pdf --template review -o references.md --print
Anti-Patterns
NEVER skip validating extracted output before saving to a database
WHY: AI extraction silently produces incorrect values when table headers are ambiguous, units are merged into cells, or multi-row headers span columns. A production gotcha is writing raw LLM output to a database without review.
BAD Pipe output directly to a database insert script. → GOOD Print results with --print, spot-check at least 3 rows against the source PDF, then save.
NEVER pass a scanned image-only PDF to PyMuPDF without warning the user
WHY: PyMuPDF extracts embedded text; it cannot OCR pixel images. A pitfall is getting empty or near-empty extraction with no error, leading to silently wrong results.
BAD Run ./scripts/extractor.py scanned.pdf --template enzyme -o out.md and trust the output. → GOOD Check that extracted text length is reasonable; if content is empty or very short, switch to --ocr mathpix.
NEVER use a custom prompt that omits output format instructions
WHY: Without explicit format instructions, the LLM may return prose summaries instead of tables, breaking downstream CSV conversion.
BAD -p "Extract protein data" → GOOD -p "Extract protein data into a Markdown table with columns: Name | PDB ID | Resolution | R-value. Use | as delimiter."
NEVER treat batch output as complete without reviewing the failed-files list
WHY: batch_extract.py continues on errors and reports failures at the end. A production pitfall is assuming a completed batch run means 100% extraction success.
BAD Count output files to verify completeness. → GOOD ALWAYS read the final summary printed by batch_extract.py; re-run failed files individually with --print to diagnose issues.
NEVER store EXTRACTOR_API_KEY in plain text in the script or a committed file
WHY: API keys in source control are a security production gotcha — they will be exposed in git history even if later removed.
BAD Hardcode api_key = "sk-ant-..." in the script. → GOOD ALWAYS use environment variables or a .env file excluded from version control.
NEVER assume Mathpix is available without checking credentials first
WHY: Mathpix requires paid credentials. Attempting OCR without MATHPIX_APP_ID and MATHPIX_APP_KEY set causes a hard failure mid-pipeline, wasting API quota already consumed for PDF upload.
BAD Use --ocr mathpix without verifying credentials. → GOOD ALWAYS confirm both MATHPIX_APP_ID and MATHPIX_APP_KEY are set before invoking Mathpix; optionally fall back to PyMuPDF.
References
- Setup: setup-and-troubleshooting.md
- Script: extractor.py
- Dependencies: requirements.txt
- Upstream: JackKuo666/sci-data-extractor
Explicit NEVER/WHY/consequence triplets with side-by-side bad/good examples. Generic warnings score low — concrete failure modes with real impact (security, correctness, performance) score high.
Runtime validation via eval scenarios proving the skill actually changes agent behaviour. Requires evals/ directory, instructions.json, ≥3 scenarios, and ≥80% instruction coverage in summary.json.
Appropriate rigidity for the skill type: strict rules for critical/security skills, balanced steps for process skills, flexible options for tool skills. Mismatched calibration (too rigid or too loose) reduces score.
Expert-only knowledge the AI couldn't derive on its own — domain-specific patterns, production gotchas, decision frameworks, and non-obvious tool behaviour. High scores mean <5% redundancy with what the model already knows.
A clear philosophy plus numbered step-by-step workflows with explicit entry/exit points. Should answer: what is the core principle, how to execute it, and when (and when not) to apply it.
Rich activation keywords and trigger scenarios in the description so the skill fires when needed. Best descriptions read like an exhaustive list of the tasks and concepts that should invoke this skill.
Copy-paste-ready code, complete runnable examples, real file paths and commands. Pseudocode and abstract descriptions score low — concrete, executable content scores high.
SKILL.md as a <100-line navigation hub pointing to focused references/ files. Content should be lazy-loaded on demand, not front-loaded. Includes actionable 'When to Use' conditions per reference.
Proper frontmatter, single-task focus, activation keywords, and cross-harness portability. Skills must work across 40+ agentic harnesses without hardcoded paths or agent-specific references.
Expert-only knowledge the AI couldn't derive on its own — domain-specific patterns, production gotchas, decision frameworks, and non-obvious tool behaviour. High scores mean <5% redundancy with what the model already knows.
A clear philosophy plus numbered step-by-step workflows with explicit entry/exit points. Should answer: what is the core principle, how to execute it, and when (and when not) to apply it.
Explicit NEVER/WHY/consequence triplets with side-by-side bad/good examples. Generic warnings score low — concrete failure modes with real impact (security, correctness, performance) score high.
Proper frontmatter, single-task focus, activation keywords, and cross-harness portability. Skills must work across 40+ agentic harnesses without hardcoded paths or agent-specific references.
SKILL.md as a <100-line navigation hub pointing to focused references/ files. Content should be lazy-loaded on demand, not front-loaded. Includes actionable 'When to Use' conditions per reference.
Appropriate rigidity for the skill type: strict rules for critical/security skills, balanced steps for process skills, flexible options for tool skills. Mismatched calibration (too rigid or too loose) reduces score.
Rich activation keywords and trigger scenarios in the description so the skill fires when needed. Best descriptions read like an exhaustive list of the tasks and concepts that should invoke this skill.
Copy-paste-ready code, complete runnable examples, real file paths and commands. Pseudocode and abstract descriptions score low — concrete, executable content scores high.
Runtime validation via eval scenarios proving the skill actually changes agent behaviour. Requires evals/ directory, instructions.json, ≥3 scenarios, and ≥80% instruction coverage in summary.json.
No eval scenarios available.
Setup and Troubleshooting
Installation
Recommended: uv
cd skills/documentation/research/sci-data-extractor
uv venv
source .venv/bin/activate
uv pip install -r requirements.txt
Alternative: standard venv
cd skills/documentation/research/sci-data-extractor
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
Verify
python3 scripts/extractor.py --help
Environment Variables
Create a .env file in the skill directory (excluded from git):
EXTRACTOR_API_KEY=your-api-key-here
EXTRACTOR_BASE_URL=https://api.anthropic.com
EXTRACTOR_MODEL=claude-sonnet-4-5-20250929
EXTRACTOR_TEMPERATURE=0.1
EXTRACTOR_MAX_TOKENS=16384
# Optional: Mathpix OCR credentials
MATHPIX_APP_ID=your-mathpix-app-id
MATHPIX_APP_KEY=your-mathpix-app-key
Load with dotenvx run -- before any command, or export variables directly.
Obtain API Keys
- Anthropic Claude: console.anthropic.com
- OpenAI-compatible: platform.openai.com/api-keys
- Mathpix OCR: api.mathpix.com
Activating the Environment
Every session requires activating the venv:
source skills/documentation/research/sci-data-extractor/.venv/bin/activate
Troubleshooting
Empty or very short extracted text
PyMuPDF extracts embedded text only. If the PDF contains scanned images rather than embedded text, the extracted content will be empty or very short. Switch to Mathpix OCR:
./scripts/extractor.py paper.pdf --template enzyme -o results.md --ocr mathpix
“API key not set” warning
Ensure EXTRACTOR_API_KEY is exported or present in .env. The script reads both EXTRACTOR_API_KEY and API_KEY environment variables.
Mathpix upload fails with HTTP 4xx
Verify that both MATHPIX_APP_ID and MATHPIX_APP_KEY are set and match your Mathpix account credentials at api.mathpix.com.
LLM returns prose instead of a table
Add explicit output format instructions to your custom prompt. For example:
-p "Extract data into a Markdown table using | as delimiter. Include columns: Name | Value | Unit"
batch_extract.py imports fail
The batch script imports from extractor using a relative import. Always run it from the scripts/ directory or ensure extractor.py is on the Python path:
cd skills/documentation/research/sci-data-extractor
python3 scripts/batch_extract.py ./literature/ ./output/ --template enzyme
Long documents exceed token limits
Increase the token limit via the environment variable:
export EXTRACTOR_MAX_TOKENS=32768
The script automatically segments long documents; increasing EXTRACTOR_MAX_TOKENS reduces the chance of truncated table output.
ImportError for fitz (PyMuPDF)
pip install pymupdf
Note: the package name is pymupdf but the import is fitz.