llm-document-extraction
Extract structured data from construction documents using LLMs. Process RFIs, submittals, contracts, specifications. Convert unstructured PDFs to structured JSON/Excel.
What this skill does
# LLM Document Extraction
## Overview
Construction documents (RFIs, submittals, specs, contracts) contain critical data trapped in unstructured formats. This skill uses LLMs to extract structured data automatically.
> "The construction industry is drowning in a flood of new data: the volume of information has grown from 15 zettabytes in 2015 to 181 zettabytes in 2025, and 90% of all existing data has been created in just the last few years." — Artem Boiko
## Use Cases
| Document Type | Extract |
|---------------|---------|
| RFI | Question, response, dates, parties |
| Submittal | Product specs, approval status, materials |
| Contract | Parties, amounts, dates, scope, clauses |
| Specification | Materials, standards, requirements |
| Daily Report | Weather, labor, equipment, progress |
## Quick Start
```python
from openai import OpenAI
import pdfplumber
import json
client = OpenAI()
def extract_from_pdf(pdf_path: str, extraction_schema: dict) -> dict:
"""Extract structured data from PDF using LLM"""
# Extract text from PDF
with pdfplumber.open(pdf_path) as pdf:
text = "\n".join(page.extract_text() for page in pdf.pages)
# Build extraction prompt
prompt = f"""
Extract the following information from this construction document.
Return ONLY valid JSON matching the schema.
Schema:
{json.dumps(extraction_schema, indent=2)}
Document:
{text[:8000]} # Truncate for context limits
JSON Output:
"""
response = client.chat.completions.create(
model="gpt-4o",
messages=[
{"role": "system", "content": "You are a construction document analyst. Extract data accurately."},
{"role": "user", "content": prompt}
],
response_format={"type": "json_object"}
)
return json.loads(response.choices[0].message.content)
```
## Extraction Schemas
### RFI Schema
```python
rfi_schema = {
"rfi_number": "string",
"date_submitted": "YYYY-MM-DD",
"date_required": "YYYY-MM-DD",
"from_company": "string",
"to_company": "string",
"subject": "string",
"question": "string",
"response": "string or null",
"status": "open|closed|pending",
"cost_impact": "boolean",
"schedule_impact": "boolean",
"attachments": ["list of attachment names"]
}
# Extract
rfi_data = extract_from_pdf("RFI-0042.pdf", rfi_schema)
```
### Submittal Schema
```python
submittal_schema = {
"submittal_number": "string",
"spec_section": "string",
"description": "string",
"manufacturer": "string",
"product_name": "string",
"model_number": "string",
"submitted_by": "string",
"date_submitted": "YYYY-MM-DD",
"status": "approved|approved_as_noted|revise_resubmit|rejected",
"reviewer_comments": "string or null",
"materials": [
{
"name": "string",
"specification": "string",
"quantity": "string"
}
]
}
```
### Contract Schema
```python
contract_schema = {
"contract_number": "string",
"project_name": "string",
"owner": {
"name": "string",
"address": "string"
},
"contractor": {
"name": "string",
"address": "string"
},
"contract_amount": "number",
"start_date": "YYYY-MM-DD",
"completion_date": "YYYY-MM-DD",
"liquidated_damages": "number per day",
"retention_percentage": "number",
"key_clauses": [
{
"clause_number": "string",
"title": "string",
"summary": "string"
}
]
}
```
## Batch Processing with n8n
```json
{
"workflow": "Document Extraction Pipeline",
"trigger": "Watch folder for new PDFs",
"nodes": [
{
"name": "Read PDF",
"type": "Read Binary Files"
},
{
"name": "Classify Document",
"type": "AI Agent",
"prompt": "Classify this document: RFI, Submittal, Contract, Spec, or Other"
},
{
"name": "Route by Type",
"type": "Switch",
"rules": ["RFI", "Submittal", "Contract", "Spec"]
},
{
"name": "Extract RFI",
"type": "OpenAI",
"schema": "rfi_schema"
},
{
"name": "Extract Submittal",
"type": "OpenAI",
"schema": "submittal_schema"
},
{
"name": "Save to Database",
"type": "PostgreSQL",
"operation": "insert"
},
{
"name": "Update Dashboard",
"type": "HTTP Request",
"method": "POST"
}
]
}
```
## Vision Model for Drawings
```python
import base64
def extract_from_drawing(image_path: str, query: str) -> str:
"""Extract information from drawings using vision model"""
with open(image_path, "rb") as f:
image_data = base64.standard_b64encode(f.read()).decode()
response = client.chat.completions.create(
model="gpt-4o",
messages=[
{
"role": "user",
"content": [
{"type": "text", "text": query},
{
"type": "image_url",
"image_url": {
"url": f"data:image/png;base64,{image_data}"
}
}
]
}
]
)
return response.choices[0].message.content
# Example: Extract room areas from floor plan
areas = extract_from_drawing(
"floor_plan.png",
"List all rooms with their areas in square meters. Return as JSON."
)
```
## RAG for Large Documents
```python
from langchain_community.document_loaders import PyPDFLoader
from langchain_text_splitters import RecursiveCharacterTextSplitter
from langchain_openai import OpenAIEmbeddings
from langchain_community.vectorstores import Qdrant
def create_document_index(pdf_path: str):
"""Create searchable index for large documents"""
# Load and split
loader = PyPDFLoader(pdf_path)
docs = loader.load()
splitter = RecursiveCharacterTextSplitter(
chunk_size=1000,
chunk_overlap=200
)
chunks = splitter.split_documents(docs)
# Create vector store
embeddings = OpenAIEmbeddings()
vectorstore = Qdrant.from_documents(
chunks,
embeddings,
collection_name="contract_docs"
)
return vectorstore
def query_document(vectorstore, question: str) -> str:
"""Query document with RAG"""
retriever = vectorstore.as_retriever(search_kwargs={"k": 5})
docs = retriever.invoke(question)
context = "\n".join(doc.page_content for doc in docs)
response = client.chat.completions.create(
model="gpt-4o",
messages=[
{"role": "system", "content": "Answer based on the contract excerpts provided."},
{"role": "user", "content": f"Context:\n{context}\n\nQuestion: {question}"}
]
)
return response.choices[0].message.content
# Usage
index = create_document_index("contract_100pages.pdf")
answer = query_document(index, "What are the liquidated damages terms?")
```
## Requirements
```bash
pip install openai pdfplumber langchain langchain-openai qdrant-client
```
## Resources
- OpenAI Vision: https://platform.openai.com/docs/guides/vision
- LangChain RAG: https://python.langchain.com/docs/tutorials/rag/
Related in AI Agents
skill-development
IncludedComprehensive meta-skill for creating, managing, validating, auditing, and distributing Claude Code skills and slash commands (unified in v2.1.3+). Provides skill templates, creation workflows, validation patterns, audit checklists, naming conventions, YAML frontmatter guidance, progressive disclosure examples, and best practices lookup. Use when creating new skills, validating existing skills, auditing skill quality, understanding skill architecture, needing skill templates, learning about YAML frontmatter requirements, progressive disclosure patterns, tool restrictions (allowed-tools), skill composition, skill naming conventions, troubleshooting skill activation issues, creating custom slash commands, configuring command frontmatter, using command arguments ($ARGUMENTS, $1, $2), bash execution in commands, file references in commands, command namespacing, plugin commands, MCP slash commands, Skill tool configuration, or deciding between skills vs slash commands. Delegates to docs-management skill for official documentation.
reprompter
IncludedTransform messy prompts into well-structured, effective prompts — single or multi-agent. Use when: "reprompt", "reprompt this", "clean up this prompt", "structure my prompt", rough text needing XML tags and best practices, "reprompter teams", "repromptception", "run with quality", "smart run", "smart agents", multi-agent tasks, audits, parallel work, anything going to agent teams. Don't use when: simple Q&A, pure chat, immediate execution-only tasks. See "Don't Use When" section for details. Outputs: Structured XML/Markdown prompt, quality score (before/after), optional team brief + per-agent sub-prompts, agent team output files. Success criteria: Single mode quality score ≥ 7/10; Repromptception per-agent prompt quality score 8+/10; all required sections present, actionable and specific.
adaptive-compaction
IncludedAdaptive add-on policy and recovery layer that decides WHEN to compact, prune, snapshot, or fork -- replacing fixed-percent auto-compaction across Claude Code, Codex, and MCP-capable hosts. Trigger on auto-compact timing or damage: "when should I compact", "is it safe to compact now or start a fresh session", "auto-compact fires too early/mid-task", "switching to an unrelated task but the window still has space", "context rot", "answers get worse the longer the session runs", "the agent forgot the plan or my decisions after it summarized", "add a layer on top that manages context without changing the agent", raising autoCompactWindow to give the policy room, or installing/tuning a cross-tool compaction policy or PreCompact hook -- even when "compaction" is never said but the problem is context-window pressure or post-summarization memory loss. Do NOT use to summarize a conversation, build RAG, write a summarization prompt (decides WHEN not HOW), or answer max-context-length trivia.
agent-skill-creator
IncludedCreate cross-platform agent skills from workflow descriptions. Activates when users ask to create an agent, automate a repetitive workflow, create a custom skill, or need advanced agent creation. Triggers on phrases like create agent for, automate workflow, create skill for, every day I have to, daily I need to, turn process into agent, need to automate, create a cross-platform skill, validate this skill, export this skill, migrate this skill. Supports single skills, multi-agent suites, transcript processing, template-based creation, interactive configuration, cross-platform export, and spec validation.
llm-wiki
IncludedUse when building or maintaining a persistent personal knowledge base (second brain) in Obsidian where an LLM incrementally ingests sources, updates entity/concept pages, maintains cross-references, and keeps a synthesis current. Triggers include "second brain", "Obsidian wiki", "personal knowledge management", "ingest this paper/article/book", "build a research wiki", "compound knowledge", "Memex", or whenever the user wants knowledge to accumulate across sessions instead of being re-derived by RAG on every query.
skill-master
IncludedAgent Skills authoring, evaluation, and optimization. Create, edit, validate, benchmark, and improve skills following the agentskills.io specification. Use when designing SKILL.md files, structuring skill folders (references, scripts, assets), ingesting external documentation into skills, running trigger evals, benchmarking skill quality, optimizing descriptions, or performing blind A/B comparisons. Keywords: agentskills.io, SKILL.md, skill authoring, eval, benchmark, trigger optimization.