npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@protocolwealthos/ai-guardrails

v0.2.0

Published

Safety primitives for calling Anthropic-style LLM APIs from regulated environments: workspace assertion, model-string allowlist, prompt-cache helpers, per-call audit row with hashed I/O

Readme

@protocolwealthos/ai-guardrails

Safety primitives for calling Anthropic-style LLM APIs from regulated environments.

Apache 2.0 · Patent Pending: USPTO #64/034,215 · part of pwos-core.

Why this exists

Off-the-shelf LLM SDKs are designed for ergonomics, not regulated use. A few of the things they don't do for you:

  • Workspace assertion — verify at boot that a credential rotation hasn't silently moved your traffic to a non-ZDR / non-data-residency workspace.
  • Model-string discipline — keep vendor model ids out of the application; resolve aliases (FRONTIER / WORKHORSE / EXTRACTION) from env at boot.
  • Prompt-cache hygiene — mark a prefix cacheable; refuse to mark a prefix cacheable if it contains client PII.
  • Content-free audit rows — record sha256(prompt), sha256(response), sha256(tool_use) plus model id, token counts, and trace id. Never raw content.

This package is the boot-time + per-request + per-response composable that gives you those four things. It does not pull in a vendor SDK.

Install

pnpm add @protocolwealthos/ai-guardrails

Quick start

import {
  assertWorkspaceFromEnv,
  createModelResolver,
  markCacheable,
  buildAuditRow,
} from "@protocolwealthos/ai-guardrails";

// 1. Boot — fail fast if credential rotation routed us to a non-ZDR workspace.
assertWorkspaceFromEnv("ws_zdr_prod", "ANTHROPIC_WORKSPACE_ID");

// 2. Boot — refuse hardcoded model literals; aliases resolve from env.
const models = createModelResolver({
  aliases: {
    FRONTIER: "CLAUDE_MODEL_FRONTIER",
    WORKHORSE: "CLAUDE_MODEL_WORKHORSE",
    EXTRACTION: "CLAUDE_MODEL_EXTRACTION",
  },
  allowedPrefixes: ["claude-"],
});

// 3. Per-request — mark the system prompt + tool prefix cacheable.
const cachedSystem = markCacheable([
  { type: "text", text: SYSTEM_PROMPT },
  { type: "text", text: TOOL_GUIDANCE },
]);

// 4. Per-response — produce a content-free audit row for the chain.
const row = buildAuditRow({
  requestId: ctx.requestId,
  actorId: ctx.actorId,
  model: models.resolve("FRONTIER"),
  modelAlias: "FRONTIER",
  request: anthropicRequest,
  response: anthropicResponse,
  traceId: langfuseTraceId,
  latencyMs: Date.now() - startedAt,
});

// Feed the row into your audit log (e.g. @protocolwealthos/audit-log).

What's in the box

| Export | Purpose | |---|---| | assertWorkspace / assertWorkspaceFromEnv | Fail-fast workspace check at boot. Default posture is block (throws); warn available for shadow modes. | | createModelResolver | Resolve application model aliases from env, with optional vendor-prefix allowlisting. | | markCacheable | Set Anthropic cache_control: { type: "ephemeral" } on the last block of a prefix. Returns a clone — never mutates. | | assertNoPiiInCachedPrefix | Wire a PII scanner into the cache boundary. The scanner is caller-supplied; pair with @protocolwealthos/pii-guard. | | buildAuditRow | Construct a content-free AiCallAuditRow from request + response. Hashes are sha256 of canonicalized JSON. | | canonicalJson / sha256Hex / hashPayload | Building blocks if you need stable hashes elsewhere. |

Designed to compose

  • Pair buildAuditRow with @protocolwealthos/audit-log — the row's hash fields are stable enough to chain.
  • Pair assertNoPiiInCachedPrefix with @protocolwealthos/pii-guard scan — supply a wrapper that returns { ok: false, reason } if scan finds an entity.
  • Pair createModelResolver with a CI lint that grep's for hardcoded model strings outside the resolver module. The lint is the second half of the discipline; the resolver alone is a habit, not an enforcement.

What this is not

  • Not a model-call SDK. Use the vendor SDK (@anthropic-ai/sdk) for transport.
  • Not a prompt-injection detector. Use @protocolwealthos/pii-guard detectInjection for that.
  • Not an observability tracer. Pass your trace id through buildAuditRow and let your tracer handle the rest.

License

Apache 2.0 with USPTO Application #64/034,215 defensive patent grant. See repo LICENSE, NOTICE, and PATENTS.txt.