llm-output-guard 1.11.1 → 1.11.3
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.
- package/README.md +13 -3
- package/dist/ai-sdk.cjs.map +1 -1
- package/dist/ai-sdk.d.cts +1 -1
- package/dist/ai-sdk.d.ts +1 -1
- package/dist/ai-sdk.js.map +1 -1
- package/dist/anthropic.cjs.map +1 -1
- package/dist/anthropic.d.cts +1 -1
- package/dist/anthropic.d.ts +1 -1
- package/dist/anthropic.js.map +1 -1
- package/dist/bin.cjs.map +1 -1
- package/dist/bin.js.map +1 -1
- package/dist/google.cjs.map +1 -1
- package/dist/google.d.cts +1 -1
- package/dist/google.d.ts +1 -1
- package/dist/google.js.map +1 -1
- package/dist/openai.cjs.map +1 -1
- package/dist/openai.d.cts +1 -1
- package/dist/openai.d.ts +1 -1
- package/dist/openai.js.map +1 -1
- package/package.json +23 -2
package/README.md
CHANGED
|
@@ -32,7 +32,7 @@ Your retry layer watches for `429`, `5xx` and timeouts. It cannot see a model th
|
|
|
32
32
|
looped until `max_tokens`, returned `{}`, stopped mid-sentence, or answered in the
|
|
33
33
|
wrong language — because all of those arrive as a **successful request**.
|
|
34
34
|
|
|
35
|
-
This produces the signal that layer is missing. Zero dependencies, ~
|
|
35
|
+
This produces the signal that layer is missing. Zero dependencies, ~6 KB min+gzip,
|
|
36
36
|
synchronous, no network.
|
|
37
37
|
|
|
38
38
|
```bash
|
|
@@ -90,9 +90,15 @@ a boolean** — you pick the line.
|
|
|
90
90
|
import OpenAI from 'openai';
|
|
91
91
|
import { withOutputGuard } from 'llm-output-guard/openai';
|
|
92
92
|
|
|
93
|
-
const client = withOutputGuard(new OpenAI(), { ...presets.chat, onDegenerate: '
|
|
93
|
+
const client = withOutputGuard(new OpenAI(), { ...presets.chat, onDegenerate: 'throw' });
|
|
94
94
|
```
|
|
95
95
|
|
|
96
|
+
`onDegenerate` decides what a failed check does: **`'throw'`** (the default)
|
|
97
|
+
fails the call, and on a stream also cancels the request. `'abort'` is the
|
|
98
|
+
streaming-only alternative — it ends the stream and keeps what arrived, and on a
|
|
99
|
+
non-streaming call it stops nothing. `'ignore'` reports and changes nothing,
|
|
100
|
+
which is how to roll out.
|
|
101
|
+
|
|
96
102
|
Adapters for the **OpenAI SDK** (both `chat.completions` and `responses`),
|
|
97
103
|
**Anthropic**, **Google Gemini** and the **Vercel AI SDK** — plus anything
|
|
98
104
|
speaking OpenAI's protocol: Groq, Together, OpenRouter, Fireworks, vLLM,
|
|
@@ -207,7 +213,9 @@ withOutputGuard(new OpenAI(), { ...presets.chat, checkPromptEcho: true });
|
|
|
207
213
|
```
|
|
208
214
|
|
|
209
215
|
Not for rewrite, translate or summarise endpoints, where copying the input is
|
|
210
|
-
the job.
|
|
216
|
+
the job. Abstains under 40 words, so a one-line prompt echoed perfectly still
|
|
217
|
+
scores 0.000.
|
|
218
|
+
[More →](docs/detectors.md#returning-the-prompt-instead-of-an-answer)
|
|
211
219
|
|
|
212
220
|
## The verdict
|
|
213
221
|
|
|
@@ -267,6 +275,8 @@ because only one of those is evidence.
|
|
|
267
275
|
## Design notes
|
|
268
276
|
|
|
269
277
|
- **Zero runtime dependencies**, enforced in CI. Node ≥ 18; works on edge, browser, Deno, Bun.
|
|
278
|
+
- **The size claim is a budget, not a memory.** `npm run size` bundles each entry, minifies and gzips it, and fails over budget — enforced in CI beside the zero-dependency check, because a number in prose is the cheapest thing in a repo to go stale.
|
|
279
|
+
- **Types resolve on old and new TypeScript alike.** Every subpath is listed in `typesVersions` as well as `exports`, so `moduleResolution: "node"` — still the default under `module: commonjs` — sees the adapters instead of only the root.
|
|
270
280
|
- **Pure and synchronous.** No network, no clock, no randomness — safe on a hot path, trivial to test.
|
|
271
281
|
- **Scores, not booleans.** Detectors report 0–1 and leave the threshold decision to you.
|
|
272
282
|
- **Abstains rather than guesses.** Samples too short to judge score 0.
|