Engineering calculations are an unforgiving domain for language models. A minor unit mismatch, a silently ignored convergence failure, or a malformed JSON payload can turn a plausible-looking report into a serious physical or operational hazard.
We have just published YamRail-Calculator (commit 29a0555, AGPL-3.0-or-later), containing two companion implementations:
-
python/— Python Reference Edition: Standard-library-only reference implementation and golden test suite. -
rust/— Rust SLM Extension Unit: A single-binary CLI (sieve-gate, ~649 KB on Windows 11 x86_64) built to sit next to local Small Language Models (SLMs) or vendor-agnostic LLM workflows without panicking on hostile or malformed inputs.
Non-Authority Notice:
YamRail-Calculatoris not a design-approval system, a Professional Engineer (PE) substitute, or a structural safety certification tool. Every emitted receipt hardcodesauthority_effect: "NONE",canonical_effect: "NONE",human_gate: "NOT_EXECUTED", andexternal_effect_allowed: false. Its sole role is to act as a deterministic checkpoint for input hygiene, contract fields, dimensional units, process-tree cleanup, and monotonic exit codes.
Standing on CMU Barati Farimani Lab's Shoulders
This work builds directly on the architectural principles and skill contracts published by the Barati Farimani Lab at Carnegie Mellon University:
- Repository: BaratiLab/mechanical-engineering-skills (audited at commit
119b1a9, MIT License) - Paper: Mechanical Engineering Skills: An Open Library of Agent Skills for Design, Analysis and Manufacturing (arXiv:2611.05758v1)
Their core rule—the model orchestrates while deterministic tools compute and return checks—is the right foundation. The upstream MIT copyright notice (Copyright (c) 2026 Amir Barati Farimani) is preserved in NOTICE, and all Rust crate licenses are enumerated in THIRD_PARTY_LICENSES.md.
What a 33/33 Static Audit Revealed
Before wiring those contracts into a local workflow, we ran a static source audit across all 33 upstream skills. Three practical friction points stood out:
-
Soft-Gate Bypass (
Exit 0on failure): 17 of 33 skills return OS exit code0with a JSON payload even when checks fail (e.g.,hard_fail: true,equilibrium_error_pct >= 1.0, or negative margin of safetystatus: "FAIL"). Downstream LLMs can easily soften or misreport those failures. -
Missing Script Gates & Fallbacks: 4 skills have no
scripts/directory (relying onSKILL.md+references/), and several skills include heuristic, synthetic, or self-judgment fallbacks when optional packages are absent. -
Copyleft Isolation Boundaries: 6 skills import GPL/LGPL libraries in-process (
gmshGPL-2.0-or-later,cadquery/OCPLGPL-2.1,shapely/GEOS LGPL-2.1), whereas OpenFOAM and FreeCAD are already isolated via CLI subprocesses.
The 3-Stage Serial Gate Architecture
To insulate probabilistic LLM/SLM orchestration from deterministic solvers—especially when small local models emit malformed JSON, out-of-range numbers, or unsafe paths—we placed three serial gates in sequence:
-
Gate 1 — Ingress Precheck (
geom-precheck, Pre-LLM): Rejects non-UTF-8 byte sequences, Shift-JIS/CRLF issues, NUL/control bytes, duplicate JSON keys,NaN/Infinity/1e309, and deeply nested JSON before data reaches downstream parsers. Emitsinput_sha256. -
Gate 2 — Pre-Solver Hook (
pre_gate): Reserved for schema/parameter screening (Pravda Screen). Until the upstream v0.5 structural fix is promoted, this gate refuses silent pass-through and forcesHOLD(Exit78mapped to Exit12INCONCLUSIVE) unless an explicit human override token is provided. -
Gate 3 — Egress Checkpoint (
sieve-gate, Post-Solver): Enforces strict monotonic exit precedence:
13 (SECURITY_VIOLATION / LEAK / TOCTOU)
> 11 (OUT_OF_SCOPE)
> 10 (REJECT)
> 12 (INCONCLUSIVE / HOLD / TAINT)
> 0 (ACCEPT)
A downstream ACCEPT (0) can never overwrite an upstream HOLD, tainted (synthetic/degraded_mode) parent receipt, or security violation.
What Destructive Testing Actually Caught
Happy-path parity tests passed early, but toxic-combination and Windows-specific destructive tests (39 cases directly injected into sieve-gate.exe, verified alongside stateless editorial/security review) surfaced real bugs before release:
-
Silent float-to-default coercion: Passing
mc_samples: 1e9as a JSON float caused.as_u64()to returnNoneand silently fall back to10_000. Now strictly rejected with Exit11. -
Windows path-escape edge cases: Beyond basic
../traversal, testing caught uncreated-leaf NTFS junctions, mixed-separator UNC paths (\/,/\), drive-relative paths (C:..\outside), and NT namespace prefixes (\??\...). All now terminate fail-closed with Exit13. -
Orphan descendant processes: Using Win32 Job Objects (
JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE), child processes that spawn grandchildren and exit0(or hang until timeout) no longer leave live orphan PIDs behind.
All 39 destructive cases ran with 0 panics and matched the Python reference implementation across 24/24 cross-implementation parity checks.
Known Limitations & Links
- Verified Environment: Current destructive and Win32 Job Object tests are verified on Windows 11 x86_64; Linux/macOS CI verification is not yet completed.
- No External Solvers Bundled: OpenFOAM, FreeCAD, Gmsh, and OpenCASCADE are not bundled or statically linked; they remain out-of-process CLI/IPC workers.
-
Bilingual Documentation: English is authoritative (
README.md, docs/WHY_YAMRAIL_INTEGRATION.md, docs/PROVENANCE_AND_AUDIT_TRAIL.md), with Japanese companions (*.ja.md) and a shared docs/BILINGUAL_NORMATIVE_GLOSSARY.md.
Repository: https://github.com/Yamrail/YamRail-Calculator/
Top comments (0)