Teams can build a validation gate with Pydantic, regex, custom middleware, and a queue. Many should. Buy a shared runtime when the cost of keeping packs, shadow rollouts, and audit rows correct across services exceeds a plan fee.
ValGuard is a runtime validation and policy-enforcement layer for LLM calls and agent steps. Deterministic rules run on every completion before the next model, tool, or customer-facing action. It is not a general workflow engine. Compare substitutes on vs and the stack map.
When building is enough
Build if most of these are true:
- One language and one deployable own the path
- A small rule set (schema + a few regexes) covers the risk
- You already have audit export and on-call for that middleware
- You do not need shadow → enforce as a product setting
- Canvas and non-Python clients will never share the packs
Pydantic and Structured Outputs are excellent parsers. They are not org policy. See vs structured outputs.
When buying is cheaper
Buy (or add a hosted gate) if most of these are true:
- Python, Node, and n8n must share the same IBAN or refund rule
- Auditors ask for rule IDs per request without a custom warehouse job
- You want shadow mode on production traffic before enforce
- Domain packs (tax IDs, invoice math, leak patterns) would take months to harden
- Fail-closed behavior must not depend on each app team's discipline
Library options still matter inside one service: vs Guardrails AI, vs NeMo Guardrails.
Cost sketch (honest)
| Approach | Cash | Hidden cost |
|---|---|---|
| DIY middleware | Infra + eng time | On-call, drift, re-implement per language |
| Open-source rails / validators | Infra + eng time | Same, plus upgrade and HA |
| Cloud filters only | Cloud SKU | Gaps on business rules; single-cloud lock-in |
| ValGuard | Plan fee | Network dependency; SaaS unless Enterprise self-host |
A Growth plan at $149/mo is often less than one engineer-week per quarter spent re-homing packs. Your numbers may differ. Do the napkin math with your on-call rate.
Architecture choice
flowchart LR
subgraph diy [DIY]
App1 --> Mid[Custom middleware]
Mid --> Model1[Model]
end
subgraph buy [Shared gate]
App2 --> VG[ValGuard]
Canvas[n8n] --> VG
VG --> Model2[Model]
end
DIY wins inside one box. A shared gate wins at the org boundary.
Failure mode comparison
| Event | DIY risk | Shared gate risk |
|---|---|---|
| New Node service | Forgets the middleware | Still hits proxy if base URL is set |
| Rule change | Redeploy every app | Update agent packs once |
| Shadow rollout | Homegrown flags | Product setting |
| Vendor outage | Your mid stays up if local | ValGuard path fails closed; Trust |
Latency
DIY in-process avoids a hop. ValGuard adds about 0.36 ms p50 on the measured HTTP path with a mocked upstream. Model time still dominates. Block/re-ask buffers streams. Methodology.
Decision checklist
- List every client that can trigger a side effect.
- List rules that must be identical across those clients.
- Estimate eng weeks to ship shadow, audit export, and packs.
- Compare to plan fee and Enterprise self-host if residency requires it.
- If DIY wins, still read LLM output validation so the contract stays explicit.
Related
Next step
If two or more runtimes share risk, start quickstart in shadow mode. If one runtime owns everything, keep building and add ValGuard later only for the gaps.