pid-to-kg

A Claude skill that reads P&ID and PFD drawings from PDF, digital or scanned, and builds a process knowledge graph: what is upstream and downstream of each item, which instrument measures what and where, and how each control loop runs from sensor to valve.

  • 131 GitHub stars
  • ⚖️ MIT

Last verified: write-up checked

pid-to-kg — skill preview

What it is

A piping and instrumentation diagram is the map of a process plant, and it normally lives in a PDF that nothing can query. Scott Duncan's skill turns a set of those sheets into a knowledge graph with three layers. Process flow records what is upstream and downstream of every tank, pump, valve and pipe segment. Measurement records which instrument measures which variable and exactly where it sits. Control records each loop from sensor through controller to final element, including I/P relays, cascades, interlocks and VFD drives. The split of labour is the interesting part. Recognising symbols and tracing lines needs visual judgement, so Claude does that: it reads the whole sheet, then every overlapping tile, and saves each sheet to its own file before the next one starts. Everything routine is done by tested Python scripts. They classify each page, render CAD exports straight from vector data, enlarge scans up to 2.5 times and boost contrast, turn pages upright, cut tiles and skip blank ones. They then split each pipe into segments between valves and fittings, link sheets through off-page connectors, and compare the tags Claude read with the PDF text or OCR. The result is summary.md, qa_report.md, graph.json and graph.duckdb under work/<plant name>/kg/. The DuckDB file supports recursive upstream and downstream searches in SQL. The author is direct about limits: extraction depends on legibility, and the output must be reviewed by a qualified engineer before any design, operations or safety use. We read the README and did not run the skill on a drawing set.

Who it's for

  • Process and controls engineers who want to ask questions of a drawing set instead of paging through it
  • Teams building an LLM context layer for a chemical or water treatment plant
  • Students learning to read P&IDs who want a checkable, traceable summary of a plant

Requirements

Requirements

  • Claude Code (desktop app or terminal)
  • Python 3.10 or newer; 3.12 is the best choice, since on 3.13 and later the OCR cross-check and automatic page orientation are missing
  • A P&ID or PFD set as PDF (the author's public datasets repo lists sets from real permitted facilities)

Setup

  1. Step 1

    bash
    On the GitHub page click Code, then Download ZIP, and unzip the file
  2. Step 2

    bash
    Open the skills folder and copy the pid-to-kg folder into your personal Claude skills folder (~/.claude/skills/ on macOS, the .claude/skills folder under your user folder on Windows)
  3. Step 3

    bash
    Make a project folder, put the P&ID PDF in it and open that folder in Claude Code

مهارة لـ Claude تقرأ مخططات الأنابيب والأجهزة (P&ID) ومخططات PFD من ملفات PDF، رقمية أو ممسوحة ضوئيا، وتبني منها رسما معرفيا للعملية الصناعية: ما الذي يسبق كل معدّة وما الذي يليها، وأي جهاز قياس يقيس ماذا وأين، وكيف تسير كل حلقة تحكم من الحساس إلى الصمام.

Examples

Convert a drawing set

Prompt
prompt
Convert `haile.pdf` into a knowledge graph. The P&IDs are on pages 47–60.

Expected output: The README's own request. The skill loads by itself; Claude asks permission before it installs Python packages or runs commands.

Trace upstream equipment

Prompt
prompt
Name all the equipment upstream of the clarifier.

Expected output: A check question you can verify on the drawings.

Find a sensor and its place

Prompt
prompt
What sensor measures the flow into TK-101, and where exactly is it?

Expected output: Every instrument is attached to the exact pipe segment or vessel it measures.

Follow a control loop

Prompt
prompt
What does FIC-0502 control, and what valve does it move?

Expected output: Loops are assembled from ISA-5.1 tags and drawn signal lines.

Pros & cons

Pros

  • Pro:Handles four page types differently: digital with searchable text, digital with outlined text, scanned, and scanned with an OCR layer
  • Pro:Unreadable items are recorded as unreadable, never guessed, and every item keeps the sheet it came from
  • Pro:A QA report lists doubts (a sensor with no location, an off-page connector with no partner) and Claude re-checks them until the report is clean
  • Pro:Four outputs with no server: summary.md, qa_report.md, graph.json and graph.duckdb; export to Neo4j or GraphML on request
  • Pro:MIT licence, with a pytest suite built on a synthetic two-sheet plant

Cons

  • Con:Machine-extracted: the README says a qualified engineer must review the graph before design, operations, management of change, or safety studies such as HAZOP or LOPA
  • Con:Low-resolution scans lose small text
  • Con:Logic that lives only in control narratives or cause-and-effect charts is not captured
  • Con:A large drawing set takes a while, because Claude reads every sheet tile by tile
  • Con:The DEXPI class mapping is informative, not a certified DEXPI export