pcb-guardrails 0.2.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pcb_guardrails-0.2.2/AGENTS.md +61 -0
- pcb_guardrails-0.2.2/CHANGELOG.md +81 -0
- pcb_guardrails-0.2.2/CITATION.cff +19 -0
- pcb_guardrails-0.2.2/LICENSE +21 -0
- pcb_guardrails-0.2.2/MANIFEST.in +4 -0
- pcb_guardrails-0.2.2/PKG-INFO +318 -0
- pcb_guardrails-0.2.2/README.md +292 -0
- pcb_guardrails-0.2.2/docs/comparison.md +67 -0
- pcb_guardrails-0.2.2/docs/incidents.md +27 -0
- pcb_guardrails-0.2.2/docs/public-boards.md +116 -0
- pcb_guardrails-0.2.2/examples/demo.py +46 -0
- pcb_guardrails-0.2.2/examples/parts.example.csv +5 -0
- pcb_guardrails-0.2.2/examples/rules.example.json +14 -0
- pcb_guardrails-0.2.2/pyproject.toml +41 -0
- pcb_guardrails-0.2.2/setup.cfg +4 -0
- pcb_guardrails-0.2.2/src/pcb_guardrails/__init__.py +2 -0
- pcb_guardrails-0.2.2/src/pcb_guardrails/__main__.py +5 -0
- pcb_guardrails-0.2.2/src/pcb_guardrails/agent_report.py +188 -0
- pcb_guardrails-0.2.2/src/pcb_guardrails/cli.py +468 -0
- pcb_guardrails-0.2.2/src/pcb_guardrails/dfm.py +311 -0
- pcb_guardrails-0.2.2/src/pcb_guardrails/dnp.py +89 -0
- pcb_guardrails-0.2.2/src/pcb_guardrails/fill.py +30 -0
- pcb_guardrails-0.2.2/src/pcb_guardrails/freeze.py +353 -0
- pcb_guardrails-0.2.2/src/pcb_guardrails/gerber.py +465 -0
- pcb_guardrails-0.2.2/src/pcb_guardrails/ipc356.py +241 -0
- pcb_guardrails-0.2.2/src/pcb_guardrails/kicad.py +265 -0
- pcb_guardrails-0.2.2/src/pcb_guardrails/libcheck.py +260 -0
- pcb_guardrails-0.2.2/src/pcb_guardrails/netcheck.py +313 -0
- pcb_guardrails-0.2.2/src/pcb_guardrails/parts.py +76 -0
- pcb_guardrails-0.2.2/src/pcb_guardrails/wrongnet.py +287 -0
- pcb_guardrails-0.2.2/src/pcb_guardrails.egg-info/PKG-INFO +318 -0
- pcb_guardrails-0.2.2/src/pcb_guardrails.egg-info/SOURCES.txt +46 -0
- pcb_guardrails-0.2.2/src/pcb_guardrails.egg-info/dependency_links.txt +1 -0
- pcb_guardrails-0.2.2/src/pcb_guardrails.egg-info/entry_points.txt +2 -0
- pcb_guardrails-0.2.2/src/pcb_guardrails.egg-info/requires.txt +5 -0
- pcb_guardrails-0.2.2/src/pcb_guardrails.egg-info/top_level.txt +1 -0
- pcb_guardrails-0.2.2/tests/conftest.py +21 -0
- pcb_guardrails-0.2.2/tests/synth.py +248 -0
- pcb_guardrails-0.2.2/tests/test_agent_report.py +83 -0
- pcb_guardrails-0.2.2/tests/test_checks.py +319 -0
- pcb_guardrails-0.2.2/tests/test_dnp.py +74 -0
- pcb_guardrails-0.2.2/tests/test_edge.py +180 -0
- pcb_guardrails-0.2.2/tests/test_freeze.py +137 -0
- pcb_guardrails-0.2.2/tests/test_ipc356.py +129 -0
- pcb_guardrails-0.2.2/tests/test_libcheck.py +121 -0
- pcb_guardrails-0.2.2/tests/test_portability.py +36 -0
- pcb_guardrails-0.2.2/tests/test_readme_demo.py +50 -0
- pcb_guardrails-0.2.2/tests/test_wrongnet.py +141 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# Rules for AI agents designing or editing PCBs
|
|
2
|
+
|
|
3
|
+
These rules come from a real board designed with an AI coding agent. Each one exists because its absence cost
|
|
4
|
+
time or nearly cost hardware. Put this file (or a link to it) where your agent reads its instructions
|
|
5
|
+
(`CLAUDE.md`, `AGENTS.md`, system prompt).
|
|
6
|
+
|
|
7
|
+
## 1. Facts come from documents, never from memory
|
|
8
|
+
|
|
9
|
+
- **Never write a pin number, pin name, footprint pad, or package dimension from memory or by guessing.**
|
|
10
|
+
Read the datasheet or the library file, and record the source (document, revision, page) next to the value.
|
|
11
|
+
If you cannot read the source, stop and ask.
|
|
12
|
+
- Check that every symbol, footprint and pin name you are about to use exists in the libraries on disk before
|
|
13
|
+
generating anything. Do not substitute a generic symbol for a real part because it is easier to place:
|
|
14
|
+
that silently deletes design information.
|
|
15
|
+
`pcb-guardrails libcheck --parts parts.csv` does the existence and pin/pad-number part of this.
|
|
16
|
+
- Active parts: confirm the minimum supply voltage from the datasheet against the **worst-case** rail, not the
|
|
17
|
+
nominal one. Part suggestions written for an earlier rail plan are a common trap.
|
|
18
|
+
- Fab capabilities (trace/space, drill, annular ring) come from the fab's current published page for the exact
|
|
19
|
+
layer count and service, never from memory.
|
|
20
|
+
|
|
21
|
+
## 2. One source of truth, and generate from it
|
|
22
|
+
|
|
23
|
+
- Keep connectivity in one human-reviewable place (a netlist table or the schematic) and generate the rest from
|
|
24
|
+
it. To change the circuit, change the source and regenerate; do not hand-patch generated files.
|
|
25
|
+
- Keep DNP decisions in the source as an explicit yes/no (`parts.csv` `dnp` column), never as prose; check them
|
|
26
|
+
with `pcb-guardrails dnp` after every regeneration.
|
|
27
|
+
- Passing every automated check only proves the source was transcribed faithfully. It does not prove the
|
|
28
|
+
source is right (a wrong resistor value or a reversed diode passes). Put review effort on the source.
|
|
29
|
+
|
|
30
|
+
## 3. Verify the deliverable, not the database
|
|
31
|
+
|
|
32
|
+
- Run `pcb-guardrails netcheck`, `fill` and `dfm` on **the exact files you will upload**, after the final export.
|
|
33
|
+
- Exit code 2 means *not checked*. Report it as such. Never summarise it as "probably fine".
|
|
34
|
+
- Prove a check can fail: when you add or change a checker, inject the fault it targets and confirm it is caught.
|
|
35
|
+
- A clean DRC is not a clean board. Gerbers plotted from a board with unfilled zones are valid files without the
|
|
36
|
+
ground plane, and no tool complains.
|
|
37
|
+
|
|
38
|
+
## 4. Do not damage production files
|
|
39
|
+
|
|
40
|
+
- Before overwriting any file, confirm it is committed (or backed up) and look at what is there.
|
|
41
|
+
- Run anything that writes (DRC with "save", zone refill with save, format upgrades, regenerators) on a **copy**.
|
|
42
|
+
One CLI "save after DRC" removed every net declaration from a board file.
|
|
43
|
+
- After a design freeze, record a hash of each frozen file and re-check it after every tool run
|
|
44
|
+
(`pcb-guardrails freeze record` / `freeze check`). Regenerating a file can change it (new UUIDs, reordered
|
|
45
|
+
items) even when the geometry is identical; `freeze check` reports that as EQUIVALENT, a real change as CHANGED.
|
|
46
|
+
Treat EQUIVALENT as a rewrite of a frozen file too: report it, and restore from the backup unless the human
|
|
47
|
+
accepts it.
|
|
48
|
+
- Do not run auto-routers or bulk "fix" operations on a frozen board.
|
|
49
|
+
|
|
50
|
+
## 5. Ask before acting when the cost of being wrong is high
|
|
51
|
+
|
|
52
|
+
- Stop and ask on any ambiguity about pinout, orientation (pin 1, mirror/chirality of a footprint), polarity,
|
|
53
|
+
voltage limits, or anything that can destroy the part. "Probably right" is not good enough for one-off hardware.
|
|
54
|
+
- Copper, footprint and hole changes after review need explicit human approval, with the reason.
|
|
55
|
+
- Ordering, purchasing, uploading to a fab, and commits are the human's actions unless explicitly delegated.
|
|
56
|
+
|
|
57
|
+
## 6. Leave a trail
|
|
58
|
+
|
|
59
|
+
- Mark every assumption in place (`# ASSUMPTION:`) and list them at the end of the task.
|
|
60
|
+
- When a decision overrides an earlier rule, record the date, who decided, and why, next to the rule.
|
|
61
|
+
- Report outcomes faithfully: failing checks with their output, skipped steps as skipped.
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
Exit codes are part of the interface (0 pass, 1 fail, 2 not checked); every change to what they mean is listed
|
|
4
|
+
under **Changed**.
|
|
5
|
+
|
|
6
|
+
## [0.2.2] — 2026-11-26
|
|
7
|
+
|
|
8
|
+
No code changes.
|
|
9
|
+
|
|
10
|
+
- Published on PyPI: `pip install pcb-guardrails`. Releases are uploaded by a GitHub Actions workflow with PyPI
|
|
11
|
+
Trusted Publishing (no API token stored anywhere); a manual run uploads to TestPyPI instead.
|
|
12
|
+
- README links point to absolute GitHub URLs, so they also work on the PyPI page.
|
|
13
|
+
- Package metadata: project URLs (repository, issues, changelog, DOI) and classifiers.
|
|
14
|
+
- README: the example output at the top is real output on synthetic boards (it was illustrative), reproducible
|
|
15
|
+
with `python examples/demo.py demo`; a test fails if the README and the tool's output differ.
|
|
16
|
+
|
|
17
|
+
## [0.2.1] — 2026-11-13
|
|
18
|
+
|
|
19
|
+
No code changes.
|
|
20
|
+
|
|
21
|
+
- Releases are archived on Zenodo, which gives each release a DOI; the author and ORCID iD come from
|
|
22
|
+
`CITATION.cff`.
|
|
23
|
+
- README: how to cite.
|
|
24
|
+
|
|
25
|
+
## [0.2.0] — 2026-11-12
|
|
26
|
+
|
|
27
|
+
### Added
|
|
28
|
+
|
|
29
|
+
- `freeze record` / `freeze check`: SHA-256 and a semantic fingerprint of each frozen file; reports SAME,
|
|
30
|
+
EQUIVALENT (rewritten, same content), CHANGED, MISSING, NEW.
|
|
31
|
+
- `wrongnet`: tracks and vias touching a pad of another net in the `.kicad_pcb`, with real pad shapes.
|
|
32
|
+
- `libcheck`: symbols and footprints must exist in the libraries on disk; symbol pins without a footprint pad.
|
|
33
|
+
- `dnp`: DNP decisions compared across `parts.csv`, schematic and board; `--exclusive` groups.
|
|
34
|
+
- `netcheck`: BREAKOUT (a plated hole only partly covered by copper on a layer), VIA-NO-HOLE (a via of the board
|
|
35
|
+
with no drill hit), net ties, pins sharing one unconnected net, pads without a symbol pin (warning).
|
|
36
|
+
- `netcheck --format agent`: a report written for an AI agent, with verdict, evidence, likely causes, next step
|
|
37
|
+
and rules; names from the design files are fenced.
|
|
38
|
+
- `netcheck --ipc356`: boards from any CAD tool, checked against their IPC-D-356 netlist (the board's nets). The
|
|
39
|
+
origin is found from the drill files or given with `--ipc356-offset`.
|
|
40
|
+
- `dfm`: copper outside the board (off the board, or crossing the edge) is judged without a rules file;
|
|
41
|
+
castellated holes are recognised and noted.
|
|
42
|
+
- Drill files: integer Excellon (digit format from the header), drill files written as Gerber X2.
|
|
43
|
+
- Validation on KiCad's 20 public demo boards (`docs/public-boards.md`) and a comparison with FabGate
|
|
44
|
+
(`docs/comparison.md`).
|
|
45
|
+
|
|
46
|
+
### Changed
|
|
47
|
+
|
|
48
|
+
- `fill` without `--min` and `dfm` without `--rules` print `MEASURED ONLY — not judged`, not `PASS`; the JSON has
|
|
49
|
+
`"judged": false`. Exit code 0.
|
|
50
|
+
- `fill --min` naming a layer that is not in the files: exit 2 (was ignored).
|
|
51
|
+
- `dfm`: a requested rule that cannot be judged (unknown name, missing file or `--pcb`), or a rules file with only
|
|
52
|
+
null rules: exit 2 unless a rule already failed (was a pass). No copper layers: exit 2.
|
|
53
|
+
- `dfm` can exit 1 without `--rules` (copper outside the board). The old check (any layer with more than 0.01 mm²
|
|
54
|
+
outside the outline, only with `--rules`) is gone.
|
|
55
|
+
- The board outline is the **centre line** of the profile strokes (was the inner side of the stroke). Board areas
|
|
56
|
+
in `fill` and copper-to-edge / hole-to-edge in `dfm` grow by about half the stroke width; cut-outs are any closed
|
|
57
|
+
loop inside the outline (was: larger than 1 mm²).
|
|
58
|
+
- `dfm`: the copper gap search reaches past the largest spacing rule.
|
|
59
|
+
- `netcheck`: `--netlist` and `--pcb` are needed unless `--ipc356` is given.
|
|
60
|
+
|
|
61
|
+
### Fixed
|
|
62
|
+
|
|
63
|
+
- Aperture macro parameters written in exponent form (`1e-05`) were rejected: exit 2 on boards with rounded
|
|
64
|
+
rectangle pads.
|
|
65
|
+
- `netcheck`: bridged solder jumpers and other net-tie footprints were reported as SHORT; no-connect pins that
|
|
66
|
+
KiCad places on one shared unconnected net were reported as SHORT.
|
|
67
|
+
- Windows: Gerber, drill and rules files were read in the locale's encoding, and a report written to a pipe in a
|
|
68
|
+
code page such as cp932 crashed on « ». Files are read as UTF-8, and output is written as UTF-8 when the
|
|
69
|
+
output's encoding is not. CI runs on Linux, macOS and Windows.
|
|
70
|
+
|
|
71
|
+
### Packaging
|
|
72
|
+
|
|
73
|
+
- License metadata as an SPDX expression (`MIT`); the source distribution includes the tests, docs, examples,
|
|
74
|
+
`AGENTS.md` and this changelog.
|
|
75
|
+
- Author metadata (`Yuki Watanabe`) in `pyproject.toml` and `LICENSE`; `CITATION.cff` for GitHub's "Cite this
|
|
76
|
+
repository".
|
|
77
|
+
|
|
78
|
+
## [0.1.0] — 2026-11-11
|
|
79
|
+
|
|
80
|
+
- `netcheck` (Gerber + drill connectivity against the KiCad schematic netlist), `fill`, `dfm`, `layers`.
|
|
81
|
+
- Rules for AI agents (`AGENTS.md`) and a Claude Code skill.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
cff-version: 1.2.0
|
|
2
|
+
message: "If you use this software, please cite it as below."
|
|
3
|
+
title: "pcb-guardrails"
|
|
4
|
+
abstract: "Independent checks of what the PCB fab actually receives (Gerber + drill vs. schematic netlist), for AI-assisted and human PCB design."
|
|
5
|
+
authors:
|
|
6
|
+
- family-names: "Watanabe"
|
|
7
|
+
given-names: "Yuki"
|
|
8
|
+
orcid: "https://orcid.org/0009-0008-1813-9517"
|
|
9
|
+
version: 0.2.2
|
|
10
|
+
doi: 10.5281/zenodo.24185580
|
|
11
|
+
license: MIT
|
|
12
|
+
repository-code: "https://github.com/Y-Watanabe11/pcb-guardrails"
|
|
13
|
+
keywords:
|
|
14
|
+
- pcb
|
|
15
|
+
- gerber
|
|
16
|
+
- kicad
|
|
17
|
+
- netlist
|
|
18
|
+
- dfm
|
|
19
|
+
- ai-agents
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Yuki Watanabe
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pcb-guardrails
|
|
3
|
+
Version: 0.2.2
|
|
4
|
+
Summary: Independent checks of what the PCB fab actually receives (Gerber + drill vs. schematic netlist), for AI-assisted and human PCB design.
|
|
5
|
+
Author: Yuki Watanabe
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/Y-Watanabe11/pcb-guardrails
|
|
8
|
+
Project-URL: Issues, https://github.com/Y-Watanabe11/pcb-guardrails/issues
|
|
9
|
+
Project-URL: Changelog, https://github.com/Y-Watanabe11/pcb-guardrails/blob/main/CHANGELOG.md
|
|
10
|
+
Project-URL: DOI, https://doi.org/10.5281/zenodo.24185580
|
|
11
|
+
Keywords: pcb,gerber,kicad,netlist,dfm,ai-agents
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Environment :: Console
|
|
14
|
+
Classifier: Intended Audience :: Science/Research
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Topic :: Scientific/Engineering :: Electronic Design Automation (EDA)
|
|
18
|
+
Requires-Python: >=3.10
|
|
19
|
+
Description-Content-Type: text/markdown
|
|
20
|
+
License-File: LICENSE
|
|
21
|
+
Requires-Dist: shapely>=2.0
|
|
22
|
+
Requires-Dist: sexpdata>=1.0
|
|
23
|
+
Provides-Extra: dev
|
|
24
|
+
Requires-Dist: pytest>=7; extra == "dev"
|
|
25
|
+
Dynamic: license-file
|
|
26
|
+
|
|
27
|
+
# pcb-guardrails
|
|
28
|
+
|
|
29
|
+
[](https://doi.org/10.5281/zenodo.24185580)
|
|
30
|
+
|
|
31
|
+
Verification guardrails for AI-assisted PCB design — independent checks of what the fab actually receives
|
|
32
|
+
(Gerber + drill vs. schematic netlist), each born from a real failure.
|
|
33
|
+
|
|
34
|
+
An AI agent (or a tired human) can produce a board whose design database looks perfect while the files sent to
|
|
35
|
+
the fab are wrong: a pour that was never filled, a layer that was not exported, a PCB that drifted from the
|
|
36
|
+
schematic, a via whose drill went missing. CAD-internal checks (DRC, ERC) look at the database. This tool looks
|
|
37
|
+
at **the deliverable**, rebuilds it from scratch, and compares it with the schematic.
|
|
38
|
+
|
|
39
|
+
A via whose drill went missing from the export. The board file still has the via, so the CAD tool sees the net
|
|
40
|
+
as connected:
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
$ pcb-guardrails netcheck demo/novia/gerbers --netlist demo/novia/board.net.xml --pcb demo/novia/board.kicad_pcb
|
|
44
|
+
pads 5, schematic nets with pads 2, copper layers 2, drill files 1
|
|
45
|
+
OPEN 1 / SHORT 0 / NO-COPPER 0 / BREAKOUT 0 / VIA-NO-HOLE 1 / pads of parts not in the schematic 0 / copper islands without pads 0
|
|
46
|
+
OPEN B: R1.1 | R2.2
|
|
47
|
+
VIA-NO-HOLE via (0.3 mm drill) at [15.0, -14.0] in the board data has no plated hole in the drill files
|
|
48
|
+
FAIL
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Inner planes plotted before the zones were filled. The Gerbers are valid files; they just have no ground plane:
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
$ pcb-guardrails fill demo/plane --min In1.Cu=0.8 --min In2.Cu=0.8
|
|
55
|
+
board area 600.0 mm2
|
|
56
|
+
F.Cu copper 0.2%
|
|
57
|
+
In1.Cu copper 0.0% FAIL (need >= 80%)
|
|
58
|
+
In2.Cu copper 0.0% FAIL (need >= 80%)
|
|
59
|
+
B.Cu copper 0.2%
|
|
60
|
+
FAIL
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Both are real output on synthetic boards (no real design involved). Reproduce them from a clone with
|
|
64
|
+
`python examples/demo.py demo`; the same export without the faults (`demo/good`) passes.
|
|
65
|
+
|
|
66
|
+
## What it checks
|
|
67
|
+
|
|
68
|
+
| Command | Catches | How |
|
|
69
|
+
|---|---|---|
|
|
70
|
+
| `netcheck` | **OPEN** (a net split into pieces), **SHORT** (two nets on one piece of copper), **NO-COPPER** (a pad with no copper in the files), **BREAKOUT** (a plated hole only partly covered by copper on a layer: a shifted or mis-registered layer), **VIA-NO-HOLE** (a via of the board with no drill hit, e.g. a lost stitching via), no-connect pins touching a net | Parses the Gerber copper layers and Excellon drills into geometry, joins copper through plated holes, and compares the resulting pieces with the **schematic** netlist. The CAD tool's connectivity engine is never used. Pad *positions* come from the `.kicad_pcb`; its nets are ignored. |
|
|
71
|
+
| `fill` | Pours / planes missing from the Gerbers (e.g. zones never filled before plotting — this exports cleanly, with no error) | Copper area per layer relative to the board area; fail below `--min LAYER=RATIO`. |
|
|
72
|
+
| `dfm` | Values below your fab's minimums; **copper outside the board** | Measures trace widths, gaps **between conductors** and **within one conductor**, copper-to-edge, drill sizes, hole-to-hole, hole-to-edge, via and PTH annular rings, silk line widths. Judges them only against a rules file **you** fill in (`--rules`). Copper entirely off the board, or crossing the board edge, fails with or without rules (see [Board edge](#board-edge)). |
|
|
73
|
+
| `freeze` | A frozen file rewritten or changed by a later tool run (a "save" that dropped nets, a regenerated board, a re-export into the upload folder) | `freeze record` stores a SHA-256 and a fingerprint of what each file means; `freeze check` reports SAME / **EQUIVALENT** (bytes differ, geometry or content identical: new UUIDs, dates, aperture numbers, item order) / **CHANGED** / MISSING / NEW. |
|
|
74
|
+
| `wrongnet` | A track or via touching a pad of **another net** in the `.kicad_pcb` (a track end on the neighbouring pad of a mirrored footprint) | Real pad shapes (rect, roundrect, oval, trapezoid, custom; absolute angles) against track and via copper, per copper layer; net-tie footprints respected. Database-side; `netcheck` sees the same short in the Gerbers. |
|
|
75
|
+
| `libcheck` | A symbol or footprint that does not exist on disk, a disabled library, a symbol pin with no footprint pad | Resolves `Library:Name` through the project and global `sym-lib-table` / `fp-lib-table` (nested tables, `${VARS}`), reads the `.kicad_sym` / `.kicad_mod`, compares pin and pad **numbers**. On a parts list before generation, or on a schematic. |
|
|
76
|
+
| `dnp` | A DNP decision that did not reach the schematic or board; alternatives fitted together | Compares the DNP flag per part across `parts.csv`, `.kicad_sch` and `.kicad_pcb`; `--exclusive A,B` groups. Unclear values in the parts list (`DNP?`, `see D1`) stop the check. |
|
|
77
|
+
| `layers` | Wrong or missing files in the upload folder | Shows how each file was classified (X2 `FileFunction`, falling back to Protel/KiCad extensions). |
|
|
78
|
+
|
|
79
|
+
Every check is proven by tests that inject one fault each into a small synthetic board — a deleted trace, an
|
|
80
|
+
extra trace, a removed via drill, a missing layer file, a shifted layer, a schematic that changed after layout,
|
|
81
|
+
a no-connect pin tied to a net, a clear-polarity cut, an unsupported Gerber feature — and assert it is reported.
|
|
82
|
+
|
|
83
|
+
## Exit codes (stable, for agents and CI)
|
|
84
|
+
|
|
85
|
+
| Code | Meaning |
|
|
86
|
+
|---|---|
|
|
87
|
+
| 0 | all checks passed; for `fill` / `dfm` run without limits, *measured only*: the output says `MEASURED ONLY — not judged` and the JSON has `"judged": false` (`dfm` still fails on copper outside the board) |
|
|
88
|
+
| 1 | a check failed |
|
|
89
|
+
| 2 | **the input could not be checked** (unsupported Gerber feature, missing file, bad arguments). Never read this as "probably fine". |
|
|
90
|
+
|
|
91
|
+
Unknown Gerber constructs stop the check with exit 2 instead of being skipped: a checker that ignores what it
|
|
92
|
+
does not understand will report a broken board as clean.
|
|
93
|
+
|
|
94
|
+
## Install
|
|
95
|
+
|
|
96
|
+
From PyPI:
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
pip install pcb-guardrails
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Or a tagged release from GitHub:
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
pip install "git+https://github.com/Y-Watanabe11/pcb-guardrails@v0.2.2"
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
From a clone, for development:
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
pip install -e ".[dev]" # with pytest
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Requires Python ≥ 3.10, `shapely` ≥ 2 and `sexpdata`.
|
|
115
|
+
|
|
116
|
+
## Quick start (KiCad)
|
|
117
|
+
|
|
118
|
+
```bash
|
|
119
|
+
kicad-cli sch export netlist --format kicadxml -o board.net.xml board.kicad_sch
|
|
120
|
+
pcb-guardrails layers fab/gerbers
|
|
121
|
+
pcb-guardrails netcheck fab/gerbers --netlist board.net.xml --pcb board.kicad_pcb --json netcheck.json --net-csv nets.csv
|
|
122
|
+
pcb-guardrails fill fab/gerbers --min In1.Cu=0.8 # a solid inner ground plane
|
|
123
|
+
pcb-guardrails dfm fab/gerbers --pcb board.kicad_pcb --rules my_fab_rules.json
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
### Other CAD tools: IPC-D-356
|
|
127
|
+
|
|
128
|
+
Any CAD tool that exports an IPC-D-356 netlist (the test netlist fabs use for electrical test) can be checked:
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
pcb-guardrails netcheck fab/gerbers --ipc356 board.ipc # instead of --netlist and --pcb
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
- The nets are **the board's**, as exported with the layout, not the schematic's. A board that drifted away from
|
|
135
|
+
its schematic is not caught in this mode; the KiCad mode compares with the schematic.
|
|
136
|
+
- The IPC file's origin often differs from the Gerbers' (KiCad writes it relative to the drill / place origin).
|
|
137
|
+
The offset is found by putting the IPC file's plated holes onto the drill hits: at least 90 % must land, and no
|
|
138
|
+
other offset may come within 10 points. Otherwise it is exit 2; give the offset with `--ipc356-offset DX,DY`
|
|
139
|
+
(mm). The offset used is printed.
|
|
140
|
+
- Read: records 317 (through-hole pad, via), 327 (surface pad, top `A01` or bottom), 367 (non-plated hole,
|
|
141
|
+
ignored), `N/C` pads (must sit alone on their copper), `UNITS CUST 0`. Anything else (other units, blind /
|
|
142
|
+
buried via records 307 / 027, conductor records) is exit 2.
|
|
143
|
+
- The format comes from two exporters and their output (KiCad's `export_d356.cpp` and KiCad 10.0.4 files, the
|
|
144
|
+
EAGLE `ipc-d-356.ulp`), not from the IPC standard, which is sold by IPC. The fields after column 32 are read by
|
|
145
|
+
their letters because the exporters place them in different columns; the drill size is not used because they
|
|
146
|
+
write it in different units.
|
|
147
|
+
- Net names are limited to 14 characters and references to 6. Nets whose names fill the field are reported as
|
|
148
|
+
possibly cut short (two different nets cut to one name are read as one net); pads whose cut reference and pin
|
|
149
|
+
repeat with different nets are kept apart as `REF#n`.
|
|
150
|
+
- Pass `--pcb` as well for a KiCad board to honour net ties; without it a net-tie footprint shows as SHORT.
|
|
151
|
+
- The IPC file says nothing about symbol pins. A footprint pad with no symbol pin (a MOSFET's drain tab) carries an
|
|
152
|
+
unconnected net of its own and shows as SHORT with the copper it joins; the KiCad mode reads the symbol's pins and
|
|
153
|
+
makes it a warning. A pad number one part repeats with a different net on each copy (KiCad does this for an
|
|
154
|
+
unconnected thermal pad and its vias), joined by the footprint's copper, is a warning, not a SHORT.
|
|
155
|
+
|
|
156
|
+
### Before and after generating a schematic / board
|
|
157
|
+
|
|
158
|
+
```bash
|
|
159
|
+
# parts.csv: ref,symbol,footprint,dnp (see examples/parts.example.csv)
|
|
160
|
+
pcb-guardrails libcheck --parts parts.csv --kicad-share <KiCad's folder with symbols/ and footprints/> \
|
|
161
|
+
--global-tables <KiCad's user config folder> # before generating
|
|
162
|
+
pcb-guardrails libcheck --parts parts.csv --sch board.kicad_sch --kicad-share ... --global-tables ...
|
|
163
|
+
pcb-guardrails dnp --parts parts.csv --sch board.kicad_sch --pcb board.kicad_pcb --exclusive R1,R2
|
|
164
|
+
pcb-guardrails wrongnet board.kicad_pcb
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
KiCad sets its library variables (`KICAD10_SYMBOL_DIR` ...) at run time and does not store them, so `libcheck`
|
|
168
|
+
needs `--kicad-share` (it maps `KICADnn_SYMBOL_DIR` to `<dir>/symbols`, `..._FOOTPRINT_DIR` to `<dir>/footprints`)
|
|
169
|
+
or `--var NAME=PATH`. On macOS that folder is `/Applications/KiCad/KiCad.app/Contents/SharedSupport` and the user
|
|
170
|
+
config folder `~/Library/Preferences/kicad/<version>`. An unresolved variable, or a library that is not in the
|
|
171
|
+
project table when no global tables were given, is exit 2, never "missing".
|
|
172
|
+
|
|
173
|
+
### Design freeze
|
|
174
|
+
|
|
175
|
+
```bash
|
|
176
|
+
pcb-guardrails freeze record fab/gerbers board.kicad_pcb board.kicad_sch -o freeze.json # at the freeze
|
|
177
|
+
pcb-guardrails freeze check freeze.json # after every tool run; exit 1 on any rewrite or change
|
|
178
|
+
pcb-guardrails freeze check freeze.json --allow-equivalent # accept rewrites that changed nothing real
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
Folders are recorded non-recursively (hidden files skipped) and new files in them are reported. Paths are stored
|
|
182
|
+
relative to the record, so commit it next to the files. What the fingerprint ignores:
|
|
183
|
+
|
|
184
|
+
| File | Fingerprint covers | Ignores |
|
|
185
|
+
|---|---|---|
|
|
186
|
+
| Gerber | the geometry after parsing (union of all objects, 0.1 µm grid) and the X2 file function | comments, attributes, dates, aperture numbers, object order, how the copper is split into objects |
|
|
187
|
+
| Excellon | every hole: plating, diameter, position, slot extent; the file function | comments, tool numbers, hole order |
|
|
188
|
+
| `.gbrjob` | the job JSON | `Header.CreationDate`, `Header.GenerationSoftware` |
|
|
189
|
+
| `.kicad_pcb` / `_sch` / `_sym` / `_mod` | the S-expression | UUID values, `uuid` / `tstamp` / `generator` entries, sibling order (kept for polygon points, stack-up, table cells), quoted vs unquoted words, `1` vs `1.0`, `(at x y 0)` vs `(at x y)` |
|
|
190
|
+
| anything else | bytes only | nothing |
|
|
191
|
+
|
|
192
|
+
A changed KiCad board also lists its item counts that changed (`net 110 -> 0`, `segment 412 -> 411`) and, for
|
|
193
|
+
boards, the number of net names used and the form of net references. A KiCad 10 format upgrade shows
|
|
194
|
+
`net_ref_form number -> name` with `net_names_used` unchanged; a real loss of nets changes `net_names_used`.
|
|
195
|
+
A format upgrade is reported as CHANGED, not EQUIVALENT: it is a different file the next tool will read.
|
|
196
|
+
|
|
197
|
+
Point the commands at **the exact folder you upload** (unzip the archive first), not at a fresh export.
|
|
198
|
+
|
|
199
|
+
### Fab rules
|
|
200
|
+
|
|
201
|
+
No fab rules are built in. Capabilities change and depend on layer count, copper weight and service tier, and
|
|
202
|
+
a wrong number baked into a checker is worse than none. Copy [`examples/rules.example.json`](https://github.com/Y-Watanabe11/pcb-guardrails/blob/main/examples/rules.example.json),
|
|
203
|
+
fill it from your fab's current capabilities page, and pass it with `--rules`.
|
|
204
|
+
|
|
205
|
+
Every non-null rule must be judged. A rule that cannot be (an unknown rule name, an edge rule without an outline
|
|
206
|
+
file, a drill rule without a drill file, a ring rule without `--pcb`, a silk rule without silkscreen files), or a file
|
|
207
|
+
whose rules are all null, is reported as NOT JUDGED and `dfm` exits 2 unless a violation already made it FAIL; set a
|
|
208
|
+
rule to null if it does not apply. Copper gaps are searched up to the largest spacing rule automatically, so a gap
|
|
209
|
+
just below your minimum cannot fall outside the search.
|
|
210
|
+
|
|
211
|
+
### Board edge
|
|
212
|
+
|
|
213
|
+
The board edge is the **centre line** of the outline strokes in the Profile / Edge_Cuts file ("the profile is the
|
|
214
|
+
center line of the stroked line": K. Tavernier, Ucamco, *The Gerber Guide, Chapter 3: The PCB Profile*, 2015).
|
|
215
|
+
Closed loops inside the outline are cut-outs. Outline arcs are followed to within 1 µm. End points closer than half
|
|
216
|
+
the stroke width are joined, since their drawn ends overlap (CAD tools round an arc's end and the next line's start
|
|
217
|
+
separately; 1 µm for an outline drawn without width). An outline that still does not close is exit 2.
|
|
218
|
+
|
|
219
|
+
`dfm` then sorts copper beyond the edge, needing no fab rule:
|
|
220
|
+
|
|
221
|
+
| Kind | Meaning | Result |
|
|
222
|
+
|---|---|---|
|
|
223
|
+
| off-board | a piece of copper with nothing on the board (a part placed beside the board, copper in a cut-out) | FAIL |
|
|
224
|
+
| over-edge | copper crossing the edge: the fab cuts through it | FAIL |
|
|
225
|
+
| castellated | copper beyond the edge around a plated hole the edge cuts | NOTE: castellation is a separate fab option, make sure it is ordered |
|
|
226
|
+
|
|
227
|
+
Copper reaching up to 5 µm past the edge counts as *at* the edge: pours drawn to the edge with zero clearance end
|
|
228
|
+
on the centre line. Whether copper may touch the edge at all is your fab's `min_copper_to_edge_mm`, which is measured
|
|
229
|
+
to the centre line, ignoring castellated pads (and `min_hole_to_edge_mm` ignores castellated holes).
|
|
230
|
+
|
|
231
|
+
## For AI agents
|
|
232
|
+
|
|
233
|
+
`netcheck --format agent` prints a report written for a language model: the verdict and exit code first, what was
|
|
234
|
+
and was not checked, and for each problem the evidence, likely causes (root causes such as undrilled vias before the
|
|
235
|
+
OPENs they cause) and the next step, including what not to do. Names of nets and parts come from the design files
|
|
236
|
+
and are printed only inside `«...»`, on one line, so a net named like an instruction cannot pass for part of the
|
|
237
|
+
report. The JSON output (`--json`) carries the same facts for programs.
|
|
238
|
+
|
|
239
|
+
- [`AGENTS.md`](https://github.com/Y-Watanabe11/pcb-guardrails/blob/main/AGENTS.md) — rules for an agent that designs or edits PCBs (pin numbers, sources of truth, what
|
|
240
|
+
never to run on production files, when to stop and ask).
|
|
241
|
+
- [`.claude/skills/pcb-guardrails/SKILL.md`](https://github.com/Y-Watanabe11/pcb-guardrails/blob/main/.claude/skills/pcb-guardrails/SKILL.md) — a Claude Code skill that
|
|
242
|
+
runs the checks before fab files are handed over and reports the result without "fixing" the Gerbers.
|
|
243
|
+
- [`docs/incidents.md`](https://github.com/Y-Watanabe11/pcb-guardrails/blob/main/docs/incidents.md) — the failures behind each check.
|
|
244
|
+
|
|
245
|
+
## Limitations
|
|
246
|
+
|
|
247
|
+
- `netcheck` against the schematic needs KiCad (XML netlist and `.kicad_pcb`); other CAD tools are checked against
|
|
248
|
+
the board's nets through IPC-D-356. `fill`, `dfm` and `freeze` read Gerber / drill files from any tool.
|
|
249
|
+
- Does not check what a pin *means* (`libcheck` compares pin and pad numbers only), footprint geometry against a datasheet, impedance,
|
|
250
|
+
current capacity, creepage/clearance for high voltage, or anything electrical beyond connectivity.
|
|
251
|
+
- Supported Gerber subset: RS-274X with X2 attributes, `%FSLA%`, mm or inch, circular/rect/obround/polygon
|
|
252
|
+
apertures, aperture macros (primitives 1, 4, 5, 20, 21), regions, multi-quadrant arcs, dark and clear
|
|
253
|
+
polarity. Step-and-repeat, image transforms (`%LM/LR/LS%`) and single-quadrant arcs stop with exit 2.
|
|
254
|
+
- Drill files: Excellon with decimal coordinates, or integer coordinates when the digit format is stated (KiCad's
|
|
255
|
+
`; FORMAT={3:3/...}` comment or a `METRIC,TZ,000.000` header; leading / trailing zero suppression or kept
|
|
256
|
+
zeros); drill files written as Gerber X2 (`TF.FileFunction,Plated|NonPlated,...`). Plating comes from X2
|
|
257
|
+
`TA.AperFunction` or the file function; a mixed file without either (KiCad's "minimal header") stops with exit 2,
|
|
258
|
+
because plated and non-plated holes cannot be told apart. Plated holes below 0.01 mm join nothing and are
|
|
259
|
+
reported (KiCad writes a 0.00001 mm via drill as `T1C0.000`).
|
|
260
|
+
- `netcheck`: footprints with `net_tie_pad_groups` (bridged solder jumpers, star-ground ties) join their nets on
|
|
261
|
+
purpose and are listed as NET-TIE, not SHORT. Pins KiCad's netlist places on one shared `unconnected-(...)` net may
|
|
262
|
+
share copper; a pin with no net must sit alone. A footprint pad the symbol has no pin for (read from the netlist's
|
|
263
|
+
`<libparts>`, e.g. a MOSFET drain tab) is a warning naming the net its copper joins, not a FAIL. Copper a footprint draws between its own pads without declaring
|
|
264
|
+
a net tie (a PCB trace fuse, for example) is a SHORT: the copper is really there.
|
|
265
|
+
- `libcheck`: KiCad-format libraries only (`.kicad_sym` files, `.pretty` folders); symbol libraries stored as a folder
|
|
266
|
+
and other library types stop with exit 2. Units of one symbol share one footprint.
|
|
267
|
+
- `wrongnet`: trapezoid pads are taken as their bounding rectangle and chamfered corners as square (both may
|
|
268
|
+
over-report, never miss). A drill offset moves the copper, not the hole (checked against KiCad's Gerber output).
|
|
269
|
+
Zones are not checked (use `netcheck` on the Gerbers).
|
|
270
|
+
- `freeze`: EQUIVALENT ignores UUID values, so a changed symbol ↔ footprint link (`path`) alone is not reported.
|
|
271
|
+
A Gerber change hidden under other copper (a trace end moved inside a pad) is EQUIVALENT, because the copper
|
|
272
|
+
is identical. Files the fingerprint cannot parse fall back to bytes only and are never EQUIVALENT.
|
|
273
|
+
|
|
274
|
+
## Tested on public boards
|
|
275
|
+
|
|
276
|
+
The 20 demo projects shipped in KiCad's source tree (`demos/`, from a 4-layer microwave board to a 1500-part VME
|
|
277
|
+
board) were exported with KiCad 10.0.4 on copies and checked, then exported again in every Gerber / drill option
|
|
278
|
+
KiCad offers. See [`docs/public-boards.md`](https://github.com/Y-Watanabe11/pcb-guardrails/blob/main/docs/public-boards.md) for the method and every finding; in short, each
|
|
279
|
+
remaining FAIL is either confirmed by KiCad's own DRC / schematic parity or is a real difference in the fab files.
|
|
280
|
+
|
|
281
|
+
## Roadmap
|
|
282
|
+
|
|
283
|
+
- v0.2 (done, see [`CHANGELOG.md`](https://github.com/Y-Watanabe11/pcb-guardrails/blob/main/CHANGELOG.md)): design-freeze fingerprints, library preflight with pin/pad
|
|
284
|
+
numbers, tracks on wrong-net pads, DNP consistency; BREAKOUT and VIA-NO-HOLE; reports for AI agents; IPC-D-356
|
|
285
|
+
for other CAD tools; the board edge as the outline's centre line; nothing unjudged is ever a pass; validated on
|
|
286
|
+
KiCad's public demo boards.
|
|
287
|
+
- Next: IPC-D-356 files from other CAD tools (only KiCad's have been tried); `--format agent` for every command;
|
|
288
|
+
speed on large boards (minutes for 5000+ pads).
|
|
289
|
+
- v0.3: assembly — JLCPCB BOM/CPL helpers and per-part rotation offsets, 1:1 footprint print templates,
|
|
290
|
+
headless LTspice batch runs.
|
|
291
|
+
|
|
292
|
+
Related: [FabGate](https://pypi.org/project/fabgate/) wraps KiCad's DRC and schematic parity in a scored gate and
|
|
293
|
+
checks that a fab package has its files; pcb-guardrails checks what is in those files. See
|
|
294
|
+
[`docs/comparison.md`](https://github.com/Y-Watanabe11/pcb-guardrails/blob/main/docs/comparison.md) for a fault-by-fault comparison.
|
|
295
|
+
|
|
296
|
+
## 日本語の概要
|
|
297
|
+
|
|
298
|
+
基板メーカーに渡すファイル(ガーバーとドリル)だけから銅のつながりを組み直し、回路図のネットリストと照合する
|
|
299
|
+
ツールです。CAD の中の検査(DRC・ERC)では見えない、書き出しの段階の間違い(塗っていないベタ、抜けた層、
|
|
300
|
+
回路図とずれた PCB、消えたビアの穴)を捕まえます。AI エージェントが基板を設計するときの安全柵として、
|
|
301
|
+
エージェント向けの規則(`AGENTS.md`)と Claude Code のスキルも同梱しています。
|
|
302
|
+
|
|
303
|
+
- 終了コードは 0 = 合格、1 = 不合格、2 = 確認できなかった(合格ではない)。判定していないものを合格とは表示しません。
|
|
304
|
+
- 回路図との照合は KiCad(XML ネットリストと `.kicad_pcb`)。他の CAD は IPC-D-356 ネットリスト(基板側のネット)で照合できます。
|
|
305
|
+
- ほかに、ベタの抜け(`fill`)、ファブの規則値との比較と基板外の銅(`dfm`)、凍結したファイルの書き換え(`freeze`)、
|
|
306
|
+
別ネットのパッドに触れる配線(`wrongnet`)、ライブラリの実在とピン番号(`libcheck`)、DNP の食い違い(`dnp`)。
|
|
307
|
+
- `netcheck --format agent` は AI エージェントが読んで動けるように、判定・証拠・原因の候補・次の手順を順に出力します。
|
|
308
|
+
- インストール: `pip install pcb-guardrails`
|
|
309
|
+
|
|
310
|
+
## Citing
|
|
311
|
+
|
|
312
|
+
If pcb-guardrails helps your work, cite it with **Cite this repository** on the GitHub page (APA or BibTeX, from
|
|
313
|
+
`CITATION.cff`). Each release is archived on Zenodo with its own DOI;
|
|
314
|
+
[10.5281/zenodo.24185580](https://doi.org/10.5281/zenodo.24185580) always points to the latest release.
|
|
315
|
+
|
|
316
|
+
## License
|
|
317
|
+
|
|
318
|
+
MIT
|