@evalguard/langchain 1.0.0

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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for describing the origin of the Work and
141
+ reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Support. While redistributing the Work or
166
+ Derivative Works thereof, You may choose to offer, and charge a
167
+ fee for, acceptance of support, warranty, indemnity, or other
168
+ liability obligations and/or rights consistent with this License.
169
+ However, in accepting such obligations, You may act only on Your
170
+ own behalf and on Your sole responsibility, not on behalf of any
171
+ other Contributor, and only if You agree to indemnify, defend,
172
+ and hold each Contributor harmless for any liability incurred by,
173
+ or claims asserted against, such Contributor by reason of your
174
+ accepting any such warranty or support.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2024-2026 EvalGuard, Inc.
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,334 @@
1
+ # @evalguard/langchain
2
+
3
+ Drop-in EvalGuard instrumentation for [LangChain](https://docs.langchain.com/) and [LangGraph](https://langchain-ai.github.io/langgraph/) in TypeScript / JavaScript.
4
+
5
+ Adds **real-time firewall (2.57ms p95), 200+ eval scorers, 300+ attack plugins, and 50 compliance frameworks** to any LangChain chain or LangGraph agent — without rewriting your code. One callback handler, full coverage.
6
+
7
+ <!-- Counts use the rounded FEATURE_COUNTS_DISPLAY forms from
8
+ packages/core/src/counts.ts so this README can't drift below the live
9
+ registry between releases (site-audit remediation 2026-07-12). -->
10
+
11
+ ## Why this exists
12
+
13
+ LangChain users already have observability via LangSmith. This package adds the surface LangSmith doesn't ship:
14
+ - Real-time input + output guardrail enforcement (block prompt injection, PII exfiltration, jailbreaks in the hot path)
15
+ - 300+ plugin adaptive red teaming (run on demand from the dashboard against your chain)
16
+ - 50 compliance frameworks (EU AI Act Annex IV, ISO 42001 SoA, SOC 2 evidence collector)
17
+ - Vendor-neutral routing across [90+ first-party LLM providers](https://evalguard.ai/docs/providers) + 800+ via aggregators (OpenRouter / LiteLLM / CometAPI)
18
+
19
+ You can run **alongside LangSmith** (both handlers in the same chain) or **replace it** by re-pointing your OTEL exporter to `https://evalguard.ai/api/v1/ingest/otlp/traces`.
20
+
21
+ ## Install
22
+
23
+ ```bash
24
+ npm install @evalguard/langchain @langchain/core @langchain/openai
25
+ ```
26
+
27
+ `@langchain/openai` is the chat model used by the examples below — swap it for
28
+ `@langchain/anthropic`, `@langchain/google-genai`, or whichever provider
29
+ package you actually use. Only `@evalguard/langchain` and `@langchain/core`
30
+ are required by the wrapper itself.
31
+
32
+ > ### ⚠️ ESM-only — requires `"type": "module"`
33
+ >
34
+ > `@evalguard/langchain` ships **ES modules only** (`"type": "module"`, no CJS build). The
35
+ > quickstart below **will not type-check or run** in a default CommonJS
36
+ > TypeScript project — you get `TS1479` ("the referenced file is an ECMAScript
37
+ > module and cannot be imported with `require`") and, because the peer SDK's
38
+ > types then resolve under a different module mode, a confusing
39
+ > `TS2345 … Property '#private' … refers to a different member` on the very
40
+ > first call.
41
+ >
42
+ > **To use this package, your consuming project must be ESM:**
43
+ >
44
+ > ```jsonc
45
+ > // package.json
46
+ > { "type": "module" }
47
+ > ```
48
+ > ```jsonc
49
+ > // tsconfig.json
50
+ > { "compilerOptions": { "module": "node16", "moduleResolution": "node16" } }
51
+ > ```
52
+ >
53
+ > **Staying on CommonJS?** Load it with a dynamic `import()`. Unlike the
54
+ > SDK-shaped wrappers (`@evalguard/openai`, `@evalguard/anthropic`,
55
+ > `@evalguard/gemini`), the handler takes no instance of a peer class across
56
+ > the boundary, and `@langchain/core` / `@langchain/openai` are dual-published,
57
+ > so your LangChain imports can stay static. Verified against
58
+ > `@langchain/core@0.3` + `@langchain/openai@0.6`.
59
+ >
60
+ > The `await` must sit **inside an async function**: top-level `await` is an
61
+ > ESM-only feature, so a bare `await import(...)` at file scope in a CJS module
62
+ > is `TS1309: The current file is a CommonJS module and cannot use 'await' at
63
+ > the top level`.
64
+ >
65
+ > ```typescript
66
+ > // ✅ compiles under module/moduleResolution "node16", no "type": "module"
67
+ > import { ChatOpenAI } from "@langchain/openai";
68
+ >
69
+ > async function main() {
70
+ > const { EvalGuardCallbackHandler } = await import("@evalguard/langchain");
71
+ > const handler = new EvalGuardCallbackHandler({
72
+ > apiKey: process.env.EVALGUARD_API_KEY!,
73
+ > projectId: "proj-123",
74
+ > });
75
+ >
76
+ > const model = new ChatOpenAI({ model: "gpt-4o", callbacks: [handler] });
77
+ > return model;
78
+ > }
79
+ >
80
+ > void main();
81
+ > ```
82
+ >
83
+ > If you swap in an LLM package that is itself ESM-only, that import has to
84
+ > become dynamic as well — the rule is that **no ESM-only specifier may be
85
+ > imported statically from a CJS file**, not just this one.
86
+ >
87
+ > Node.js ≥ 22.12 can also `require()` an ESM module directly
88
+ > (`require(esm)`), but TypeScript still type-checks the import under CJS
89
+ > rules, so the dynamic-import form above is the supported path.
90
+
91
+ `@langchain/core` is a peer dependency — the wrapper compiles without it, so you can install lazily.
92
+
93
+ ## Usage
94
+
95
+ ### Per-model handler
96
+
97
+ ```ts
98
+ import { ChatOpenAI } from "@langchain/openai";
99
+ import { EvalGuardCallbackHandler } from "@evalguard/langchain";
100
+
101
+ const handler = new EvalGuardCallbackHandler({
102
+ apiKey: process.env.EVALGUARD_API_KEY!,
103
+ projectId: "proj-123", // optional
104
+ blockOnViolation: true, // default: true
105
+ metadata: { env: "prod" }, // optional, attached to every trace
106
+ });
107
+
108
+ const model = new ChatOpenAI({
109
+ model: "gpt-4o",
110
+ callbacks: [handler],
111
+ });
112
+
113
+ const result = await model.invoke("Summarise this email…");
114
+ ```
115
+
116
+ ### Global env-based install
117
+
118
+ ```ts
119
+ import { autoInstall } from "@evalguard/langchain";
120
+
121
+ const handler = autoInstall();
122
+ // Reads EVALGUARD_API_KEY + EVALGUARD_PROJECT_ID + EVALGUARD_BASE_URL.
123
+ // Returns null if EVALGUARD_API_KEY is unset (safe to call at module load).
124
+ ```
125
+
126
+ Then pass `handler` to any chain's `callbacks` array, or attach globally via `setGlobalCallbacks([handler])` from `@langchain/core/callbacks/manager`.
127
+
128
+ ### LangGraph
129
+
130
+ The same handler covers LangGraph — node-level events (`handleChainStart`, `handleToolStart`, `handleAgentAction`) emit nested spans so the trace tree mirrors your graph topology.
131
+
132
+ LangGraph ships in its own package, so install it alongside the wrapper:
133
+
134
+ ```bash
135
+ npm install @langchain/langgraph
136
+ ```
137
+
138
+ A complete graph, start to finish. The handler goes in the `RunnableConfig` you
139
+ pass to `invoke`, which is what makes every node in the graph — not just the
140
+ top-level call — emit a span:
141
+
142
+ <!-- langgraph:example -->
143
+
144
+ ```ts
145
+ import { StateGraph, StateSchema, MessagesValue, START, END } from "@langchain/langgraph";
146
+ import { AIMessage, HumanMessage } from "@langchain/core/messages";
147
+ import { EvalGuardCallbackHandler } from "@evalguard/langchain";
148
+
149
+ const handler = new EvalGuardCallbackHandler({ apiKey: process.env.EVALGUARD_API_KEY! });
150
+
151
+ const State = new StateSchema({ messages: MessagesValue });
152
+
153
+ const app = new StateGraph(State)
154
+ .addNode("respond", (state) => ({
155
+ messages: [new AIMessage(`echo: ${state.messages.at(-1)?.text ?? ""}`)],
156
+ }))
157
+ .addEdge(START, "respond")
158
+ .addEdge("respond", END)
159
+ .compile();
160
+
161
+ const result = await app.invoke(
162
+ { messages: [new HumanMessage("Summarise this email…")] },
163
+ { callbacks: [handler] },
164
+ );
165
+
166
+ console.log(result.messages.at(-1)?.text);
167
+ ```
168
+
169
+ <!-- /langgraph:example -->
170
+
171
+ <sub>Until 2026-08-03 this block referenced an undeclared `workflow` and wrote
172
+ `{ messages: [...] }` with a literal `...` — `TS1109: Expression expected`. It
173
+ never compiled, and LangGraph is a headline feature of this package. On
174
+ 2026-08-03 the replacement above was type-checked **and executed** verbatim
175
+ against `@langchain/langgraph@1.4.8` + `@langchain/core@1.2.4`, from the packed
176
+ tarball in a clean ESM consumer, `module`/`moduleResolution` `node16` +
177
+ `strict`; it prints `echo: Summarise this email…` and emits three EvalGuard
178
+ spans. That was a one-time check, not a CI gate — the `langgraph:example`
179
+ anchors are there so the block can be extracted and re-run verbatim, which is
180
+ the only way this stays true. Swap the `respond` node for a real chat model and
181
+ the same `handler` covers its LLM span too.</sub>
182
+
183
+ ## Config
184
+
185
+ | Option | Default | Notes |
186
+ |---|---|---|
187
+ | `apiKey` | required | Your EvalGuard API key. |
188
+ | `projectId` | none | Tags every trace with a project. Visible in the dashboard. |
189
+ | `baseUrl` | `https://evalguard.ai/api/v1` | Override for self-hosted deployments. |
190
+ | `blockOnViolation` | `true` | When `true`, guardrail violations throw `EvalguardBlockedError` and abort the LangChain run. When `false`, violations are logged but the call proceeds. |
191
+ | `disableLogging` | `false` | Skip trace logging entirely (guardrails still run). |
192
+ | `disableGuardrails` | `false` | Skip pre-call firewall (tracing still runs). Setting this **and** `blockOnViolation: true` throws `EvalguardConfigError` at construction — with the firewall off there is nothing to block on, and silently accepting the pair would leave you believing you are protected. |
193
+ | `metadata` | `{}` | Free-form fields attached to every trace. |
194
+
195
+ ### How blocking is actually enforced
196
+
197
+ LangChain swallows callback-handler exceptions by default, and by default does
198
+ not even *await* the handler — so a handler that merely throws is a no-op and
199
+ the model call proceeds. This handler therefore declares the two flags
200
+ LangChain reads off the instance, `awaitHandlers = true` and
201
+ `raiseError = true`, which is what makes the throw abort the run. Enforcement
202
+ is verified end-to-end against a real `@langchain/core` chat model through
203
+ `invoke`, `stream` and a `RunnableSequence` in
204
+ `src/__tests__/blocking-enforcement.test.ts`.
205
+
206
+ Two consequences worth knowing:
207
+
208
+ - **An unreadable prompt is rejected, not skipped.** If the handler cannot
209
+ extract the prompt text (for example a custom message class whose
210
+ `_getType()` throws), it fails **closed** with a `prompt_unreadable`
211
+ violation rather than letting an unscanned prompt reach the model. With
212
+ `blockOnViolation: false` the call proceeds and the trace records that
213
+ nothing was scanned. The prompt is never partially scanned or truncated.
214
+ - **Only the guardrail decision can abort your run.** Model-name resolution
215
+ degrades to `"unknown"`, and every trace-logging hook is contained, so a
216
+ logging failure never bubbles into your chain.
217
+
218
+ ## What's traced
219
+
220
+ Every LangChain run emits to EvalGuard with:
221
+ - **LLM spans** — input, output, model, latency, token usage, cost (priced via the same table as openai-wrapper / anthropic-wrapper)
222
+ - **Chain spans** — Runnable + LangGraph node entry/exit
223
+ - **Tool spans** — every `Tool.invoke` or LangGraph tool node
224
+ - **Agent actions** — chosen tool + input for each agent step
225
+
226
+ All spans carry **OpenInference-compliant attributes** (`openinference.span.kind`, `llm.model_name`, `llm.token_count.*`, `input.value`, `output.value`, `status.code`). This means the same traces render natively in [Phoenix](https://github.com/Arize-ai/phoenix), [Arize AX](https://arize.com/docs/ax), and any OpenInference-aware viewer.
227
+
228
+ ## Outage semantics — fail-CLOSED by default
229
+
230
+ > Corrected 2026-07-29. This section previously documented a fail-**open**
231
+ > contract ("lets the LangChain call proceed — guardrails default-allow on
232
+ > error"). That has not been true since 2026-05-28, when the wrappers moved
233
+ > to fail-closed. Customers reading this were told a security control
234
+ > degrades safely when it does the opposite.
235
+
236
+ If EvalGuard is unreachable (network blip, our outage, DNS hiccup), this
237
+ wrapper's behaviour depends on `blockOnViolation`:
238
+
239
+ | `blockOnViolation` | Guardrail unreachable | Real violation detected |
240
+ |---|---|---|
241
+ | `true` (**default**) | **Blocks** — throws `EvalguardBlockedError` with a `guardrail_unavailable` violation | Blocks — throws `EvalguardBlockedError` |
242
+ | `false` | Call proceeds, violation recorded on the trace | Call proceeds, violation recorded on the trace |
243
+
244
+ Trace logging always fails silently either way — a trace-log failure never
245
+ bubbles into your chain.
246
+
247
+ If you need availability-first behaviour, set `blockOnViolation: false`.
248
+ The legacy global escape hatch `EVALGUARD_GUARDRAIL_FAIL_OPEN_LEGACY=1`
249
+ restores pre-2026-05-28 fail-open for every wrapper in the process; it
250
+ prints a one-time warning and is not recommended.
251
+
252
+ Same contract as our `openai-wrapper`, `anthropic-wrapper`,
253
+ `gemini-wrapper`, `vercel-ai-wrapper`, and `llamaindex-wrapper`.
254
+
255
+ ## Blocking errors
256
+
257
+ When `blockOnViolation: true` (default), policy violations throw `EvalguardBlockedError`:
258
+
259
+ ```ts
260
+ import { EvalGuardCallbackHandler, EvalguardBlockedError } from "@evalguard/langchain";
261
+
262
+ try {
263
+ const result = await chain.invoke({ input: userMessage });
264
+ } catch (err) {
265
+ if (err instanceof EvalguardBlockedError) {
266
+ console.log("Blocked:", err.violations);
267
+ // err.violations: [{ type, severity, message }]
268
+ return "I can't help with that.";
269
+ }
270
+ throw err;
271
+ }
272
+ ```
273
+
274
+ ## Migrating from LangSmith
275
+
276
+ Already on LangSmith? Two paths:
277
+
278
+ **Coexist (recommended for evaluating):**
279
+ Keep your existing `LangChainTracer` in the callbacks array; add `EvalGuardCallbackHandler` alongside. Both will receive the same events; LangSmith continues to populate its dashboard while EvalGuard adds firewall + red-teaming + compliance.
280
+
281
+ **Replace:**
282
+ Remove the LangSmith tracer. Re-point your OTEL exporter:
283
+
284
+ ```bash
285
+ # Before
286
+ OTEL_EXPORTER_OTLP_ENDPOINT=https://api.smith.langchain.com/otel/
287
+
288
+ # After (full traces path — use the signal-specific env var)
289
+ OTEL_EXPORTER_OTLP_TRACES_ENDPOINT=https://evalguard.ai/api/v1/ingest/otlp/traces
290
+ OTEL_EXPORTER_OTLP_HEADERS=Authorization=Bearer%20${EVALGUARD_API_KEY}
291
+ ```
292
+
293
+ We accept OpenInference-shaped spans natively, so traces emitted via LangChain's existing OTel integration continue to flow.
294
+
295
+ ## Cost estimates: unpriced models are reported as unpriced
296
+
297
+ `estimateCost()` used to invent a price for any model outside a ~60-row table:
298
+ `estimateCost("gpt-5", 1000, 500)` and `estimateCost("totally-unknown-model",
299
+ 1000, 500)` both returned `0.0105` from a blended $0.003/$0.015-per-1k
300
+ fallback — with no flag and no warning. A FinOps figure you cannot tell apart
301
+ from a real vendor price is worse than no figure at all.
302
+
303
+ Two things changed:
304
+
305
+ - **Coverage** — 2,200+ model ids now resolve to a real, sourced rate
306
+ (generated from EvalGuard's own pricing database, which is synced from the
307
+ LiteLLM catalogue). `gpt-5` is priced correctly.
308
+ - **Honesty** — a genuinely unknown model is now *visibly* unknown.
309
+
310
+ ```typescript
311
+ import { estimateCostDetailed, isModelPriced } from "@evalguard/langchain";
312
+
313
+ estimateCostDetailed("gpt-5", 1000, 500);
314
+ // { model: "gpt-5", costUsd: 0.00625, priced: true, pricingSource: "catalog" }
315
+
316
+ estimateCostDetailed("totally-unknown-model", 1000, 500);
317
+ // { model: "totally-unknown-model",
318
+ // costUsd: null, // <- never a fabricated number
319
+ // priced: false,
320
+ // pricingSource: "unpriced",
321
+ // blendedFallbackUsd: 0.0105 } // <- opt-in rough figure, clearly labelled
322
+
323
+ isModelPriced("totally-unknown-model"); // false
324
+ ```
325
+
326
+ `estimateCost()` still returns a `number` for backwards compatibility, but it
327
+ now emits a one-time `console.warn` naming the unpriced model. Traces carry
328
+ `costPricingSource` alongside `cost`, and `cost` is `null` for an unpriced
329
+ model rather than a guess, so your EvalGuard dashboard shows "unpriced" instead
330
+ of a fake dollar amount.
331
+
332
+ ## License
333
+
334
+ Apache-2.0
package/dist/cost.d.ts ADDED
@@ -0,0 +1,4 @@
1
+ export { estimateCost } from "@evalguard/wrapper-core";
2
+ export { estimateCostDetailed, isModelPriced } from "@evalguard/wrapper-core";
3
+ export type { CostEstimate, PricingSource } from "@evalguard/wrapper-core";
4
+ //# sourceMappingURL=cost.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cost.d.ts","sourceRoot":"","sources":["../src/cost.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAMvD,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAC9E,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC"}
package/dist/cost.js ADDED
@@ -0,0 +1,18 @@
1
+ // Cost estimation is shared across all EvalGuard wrappers — re-exported from
2
+ // @evalguard/wrapper-core so the model pricing table has a single source of
3
+ // truth (as anthropic-wrapper/src/cost.ts and openai-wrapper/src/cost.ts
4
+ // already do).
5
+ //
6
+ // This file used to carry its OWN partial price table that returned 0 for any
7
+ // model it didn't list. That silently contradicts wrapper-core's explicit
8
+ // policy — an unknown model falls back to a conservative $0.003/$0.015 per 1k
9
+ // because reporting 0 is worse than slightly-off: it MASKS the bill. A customer
10
+ // on a model missing from the local table (claude-sonnet-4-5, gpt-5, any new
11
+ // release) saw $0.00 spend in every trace while burning real provider budget.
12
+ export { estimateCost } from "@evalguard/wrapper-core";
13
+ // 2026-07-30 (audit finding 5): `estimateCostDetailed` is re-exported alongside
14
+ // it. The blended fallback above is no longer SILENT — an unpriced model now
15
+ // reports `{ costUsd: null, priced: false }` instead of a number a customer
16
+ // cannot tell apart from a real vendor price.
17
+ export { estimateCostDetailed, isModelPriced } from "@evalguard/wrapper-core";
18
+ //# sourceMappingURL=cost.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cost.js","sourceRoot":"","sources":["../src/cost.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,4EAA4E;AAC5E,yEAAyE;AACzE,eAAe;AACf,EAAE;AACF,8EAA8E;AAC9E,0EAA0E;AAC1E,8EAA8E;AAC9E,gFAAgF;AAChF,6EAA6E;AAC7E,8EAA8E;AAC9E,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAEvD,gFAAgF;AAChF,6EAA6E;AAC7E,4EAA4E;AAC5E,8CAA8C;AAC9C,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { GuardrailClient } from "@evalguard/wrapper-core";
2
+ export type { GuardrailCheckResult, GuardrailViolation, TraceLogData, } from "@evalguard/wrapper-core";
3
+ //# sourceMappingURL=guardrail-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guardrail-client.d.ts","sourceRoot":"","sources":["../src/guardrail-client.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,YAAY,EACV,oBAAoB,EACpB,kBAAkB,EAClB,YAAY,GACb,MAAM,yBAAyB,CAAC"}
@@ -0,0 +1,15 @@
1
+ // ── EvalGuard Guardrail Client (LangChain variant) ─────────────────────────
2
+ // Converged onto @evalguard/wrapper-core's canonical GuardrailClient (#40,
3
+ // 2026-06-24). This wrapper previously shipped its OWN copy of the client,
4
+ // whose logTrace built a flat /traces payload the server matched against
5
+ // NEITHER its OTLP nor its legacy branch — so every LangChain trace was
6
+ // silently rejected, AND the copy lacked the traceId/idempotencyKey fields the
7
+ // shared client carries. Re-exporting the canonical client fixes the trace
8
+ // payload (steps[]+metadata the server understands), gives retry +
9
+ // circuit-breaker + idempotency for free, and preserves the OpenInference
10
+ // sidecar (now a first-class TraceLogData field forwarded into metadata).
11
+ //
12
+ // wrapper-core has zero runtime deps, so the single-package install footprint
13
+ // is unchanged.
14
+ export { GuardrailClient } from "@evalguard/wrapper-core";
15
+ //# sourceMappingURL=guardrail-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guardrail-client.js","sourceRoot":"","sources":["../src/guardrail-client.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAC9E,2EAA2E;AAC3E,2EAA2E;AAC3E,yEAAyE;AACzE,wEAAwE;AACxE,+EAA+E;AAC/E,2EAA2E;AAC3E,mEAAmE;AACnE,0EAA0E;AAC1E,0EAA0E;AAC1E,EAAE;AACF,8EAA8E;AAC9E,gBAAgB;AAChB,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC"}