Skip to content

docs: add RFC-2 — mid-stream LLM guardrails design doc - #31

Merged
ykstorm merged 1 commit into
mainfrom
docs/add-rfc-tripwire-2026-07-18
Jul 19, 2026
Merged

docs: add RFC-2 — mid-stream LLM guardrails design doc#31
ykstorm merged 1 commit into
mainfrom
docs/add-rfc-tripwire-2026-07-18

Conversation

@ykstorm

@ykstorm ykstorm commented Jul 18, 2026

Copy link
Copy Markdown
Owner

What

Adds docs/rfc-tripwire.md — RFC-2, the design document for Tripwire's
mid-stream guardrail: a per-chunk streaming guard that aborts on a
hard-policy match before the offending token is yielded.

Why

The behavior shipped in @ykstormsorg/tripwire v1.1.0 (StreamingGuard /
createStreamingGuard, src/streaming/index.ts) had no written design
rationale in-repo. This RFC records the motivation (irreversible mid-stream
delivery), the two-tier abort/observe severity model, the ~4.7µs/chunk
CI-measured cost basis, alternatives considered, prior art, open questions,
and rollout.

Scope

Docs only. No code, no dependency, no behavior change. One new file, additive.

Notes

  • Design references cite live source lines in src/streaming/index.ts and src/check.ts.
  • Per-chunk cost figure (~4.7µs) is the CI benchmark number published by .github/workflows/benchmark.yml.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9b6eaab4e6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread docs/rfc-tripwire.md Outdated

**Mechanism.** `StreamingGuard` wraps the token stream. `onChunk(chunk)` appends to an accumulated buffer and evaluates the pattern list against the buffer on every call (`src/streaming/index.ts:108`). Each pattern carries a mode — abort or observe (`:64`). On an abort match, the guard throws immediately (`:126`), before the token propagates; on an observe match, it pushes a violation and continues (`:128`). The buffer is trimmed to a window so the match cost does not grow with response length (`:117`).

**Data model.** A pattern is a compiled regex plus a label plus a mode (`abort | observe`). Default patterns cover contact-info leaks and non-existent business entities as abort; placeholders, markdown artifacts, and price-commitment language as observe. Callers extend or override via a factory (`createStreamingGuard`). The guard holds the accumulated buffer, the pattern list, an `onViolate` handler, and an `onAbort` handler.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Correct the default abort coverage

This documents default streaming abort coverage for “non-existent business entities,” but the built-in abort list only contains CONTACT_LEAK_PATTERN and BUSINESS_LEAK_PATTERN (src/streaming/index.ts:83-97), and the business pattern is for commission/partner-status text (src/patterns/business.ts), not invented projects/builders. In production, users relying on this RFC could believe entity fabrication is prevented mid-stream when those checks are only post-hoc/batch-style, so this should describe the shipped coverage accurately or add the missing streaming rule.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amended the RFC to describe the actual streaming abort coverage — contact-info leaks (CONTACT_LEAK_PATTERN) and business-sensitive leaks, i.e. commission-rate / partner-status text (BUSINESS_LEAK_PATTERN, src/patterns/business.ts). Entity fabrication is caught in the batch checkResponse scope (src/check.tsHALLUCINATION: invented names, FABRICATED_BUILDER), not mid-stream. The Rollout section carried the same overclaim; fixed that too. Thanks for the catch.

@ykstorm
ykstorm force-pushed the docs/add-rfc-tripwire-2026-07-18 branch from 9b6eaab to 3a45c65 Compare July 19, 2026 17:39
@ykstorm
ykstorm merged commit 8817dd9 into main Jul 19, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant