@outputai/evals 0.1.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 the 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 reasonable and customary use in describing the
141
+ origin of the Work and 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 Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
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 [yyyy] [name of copyright owner]
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,11 @@
1
+ # @outputai/evals
2
+
3
+ Offline evaluation framework for Output.ai workflows.
4
+
5
+ [![npm version](https://img.shields.io/npm/v/@outputai/evals)](https://www.npmjs.com/package/@outputai/evals)
6
+
7
+ ## Documentation
8
+ - [README](https://docs.output.ai/packages/evals)
9
+ - [API Reference](https://output-ai-reference-code-docs.onrender.com/modules/evals_src.html)
10
+
11
+ <!-- Internal Dev Note: The documentation for this package is found at docs/guides/packages/evals.mdx -->
@@ -0,0 +1,2 @@
1
+ import type { EvaluatorResult, Verdict } from './schemas.js';
2
+ export declare function aggregateCaseVerdict(evaluatorResults: EvaluatorResult[]): Verdict;
@@ -0,0 +1,11 @@
1
+ import { VERDICT, CRITICALITY } from './schemas.js';
2
+ export function aggregateCaseVerdict(evaluatorResults) {
3
+ const required = evaluatorResults.filter(r => r.criticality === CRITICALITY.REQUIRED);
4
+ if (required.some(r => r.verdict === VERDICT.FAIL)) {
5
+ return VERDICT.FAIL;
6
+ }
7
+ if (required.some(r => r.verdict === VERDICT.PARTIAL)) {
8
+ return VERDICT.PARTIAL;
9
+ }
10
+ return VERDICT.PASS;
11
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,48 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { aggregateCaseVerdict } from './aggregate.js';
3
+ const makeResult = (verdict, criticality = 'required') => ({
4
+ name: 'test_eval',
5
+ verdict,
6
+ criticality
7
+ });
8
+ describe('aggregateCaseVerdict', () => {
9
+ it('returns pass when all required evaluators pass', () => {
10
+ expect(aggregateCaseVerdict([
11
+ makeResult('pass'),
12
+ makeResult('pass')
13
+ ])).toBe('pass');
14
+ });
15
+ it('returns fail when any required evaluator fails', () => {
16
+ expect(aggregateCaseVerdict([
17
+ makeResult('pass'),
18
+ makeResult('fail')
19
+ ])).toBe('fail');
20
+ });
21
+ it('returns partial when any required evaluator is partial and none fail', () => {
22
+ expect(aggregateCaseVerdict([
23
+ makeResult('pass'),
24
+ makeResult('partial')
25
+ ])).toBe('partial');
26
+ });
27
+ it('returns fail over partial when both exist', () => {
28
+ expect(aggregateCaseVerdict([
29
+ makeResult('partial'),
30
+ makeResult('fail')
31
+ ])).toBe('fail');
32
+ });
33
+ it('ignores informational evaluators for verdict', () => {
34
+ expect(aggregateCaseVerdict([
35
+ makeResult('pass'),
36
+ makeResult('fail', 'informational')
37
+ ])).toBe('pass');
38
+ });
39
+ it('returns pass when only informational evaluators fail', () => {
40
+ expect(aggregateCaseVerdict([
41
+ makeResult('fail', 'informational'),
42
+ makeResult('partial', 'informational')
43
+ ])).toBe('pass');
44
+ });
45
+ it('returns pass for empty evaluator list', () => {
46
+ expect(aggregateCaseVerdict([])).toBe('pass');
47
+ });
48
+ });
@@ -0,0 +1,20 @@
1
+ import type { InterpretConfig, EvalOutput, Dataset, Criticality } from './schemas.js';
2
+ export interface EvalDefinition {
3
+ evaluator: Function;
4
+ criticality?: Criticality;
5
+ interpret: InterpretConfig;
6
+ }
7
+ export interface EvalWorkflowConfig {
8
+ concurrency?: number;
9
+ }
10
+ export type EvalWorkflowInput = {
11
+ datasets: Dataset[];
12
+ };
13
+ export type EvalWorkflowFn = (input: EvalWorkflowInput, context: unknown) => Promise<EvalOutput>;
14
+ export interface EvalWorkflowOptions {
15
+ name: string;
16
+ evals: EvalDefinition[];
17
+ fn?: EvalWorkflowFn;
18
+ config?: EvalWorkflowConfig;
19
+ }
20
+ export declare function evalWorkflow({ name, evals, fn, config }: EvalWorkflowOptions): unknown;
@@ -0,0 +1,88 @@
1
+ import { workflow, executeInParallel, z } from '@outputai/core';
2
+ import { getMetadata } from '@outputai/core/sdk_utils';
3
+ import { VERDICT, CRITICALITY, DatasetSchema, EvalOutputSchema } from './schemas.js';
4
+ import { interpretResult } from './interpret.js';
5
+ import { aggregateCaseVerdict } from './aggregate.js';
6
+ export function evalWorkflow({ name, evals, fn, config = {} }) {
7
+ const concurrency = config.concurrency ?? 10;
8
+ const evalDefs = evals.map(def => {
9
+ const meta = getMetadata(def.evaluator);
10
+ if (!meta) {
11
+ throw new Error('Evaluator passed to evalWorkflow is missing metadata. Ensure it was created with evaluator().');
12
+ }
13
+ return {
14
+ name: meta.name,
15
+ criticality: def.criticality ?? CRITICALITY.REQUIRED,
16
+ interpret: def.interpret
17
+ };
18
+ });
19
+ const defaultFn = async function (input) {
20
+ const { invokeEvaluator } = this;
21
+ const jobs = input.datasets.map((dataset) => async () => {
22
+ const evaluatorResults = [];
23
+ for (const evalDef of evalDefs) {
24
+ const { evals: perEvalTruth, ...globalTruth } = dataset.ground_truth ?? {};
25
+ const evalTruth = perEvalTruth?.[evalDef.name] ?? {};
26
+ const mergedTruth = { ...globalTruth, ...evalTruth };
27
+ const result = await invokeEvaluator(evalDef.name, {
28
+ input: dataset.input,
29
+ output: dataset.last_output?.output,
30
+ ground_truth: mergedTruth
31
+ });
32
+ const verdict = interpretResult(result, evalDef.interpret);
33
+ evaluatorResults.push({
34
+ name: evalDef.name,
35
+ verdict,
36
+ criticality: evalDef.criticality,
37
+ confidence: result.confidence,
38
+ reasoning: result.reasoning,
39
+ feedback: result.feedback?.length ? result.feedback : undefined
40
+ });
41
+ }
42
+ const caseVerdict = aggregateCaseVerdict(evaluatorResults);
43
+ return {
44
+ datasetName: dataset.name,
45
+ verdict: caseVerdict,
46
+ evaluators: evaluatorResults
47
+ };
48
+ });
49
+ const results = await executeInParallel({ jobs, concurrency });
50
+ const cases = results.map((r, i) => {
51
+ if (r.ok) {
52
+ return r.result;
53
+ }
54
+ const datasetName = input.datasets[i]?.name ?? `dataset_${i}`;
55
+ return {
56
+ datasetName,
57
+ verdict: VERDICT.FAIL,
58
+ evaluators: [{
59
+ name: '_error',
60
+ verdict: VERDICT.FAIL,
61
+ criticality: CRITICALITY.REQUIRED,
62
+ reasoning: r.error instanceof Error ? r.error.message : String(r.error)
63
+ }]
64
+ };
65
+ });
66
+ const passed = cases.filter(c => c.verdict === VERDICT.PASS).length;
67
+ const partial = cases.filter(c => c.verdict === VERDICT.PARTIAL).length;
68
+ const failed = cases.filter(c => c.verdict === VERDICT.FAIL).length;
69
+ const total = cases.length;
70
+ return {
71
+ cases,
72
+ summary: {
73
+ total,
74
+ passed,
75
+ partial,
76
+ failed,
77
+ acceptableRate: total > 0 ? (passed + partial) / total : 0
78
+ }
79
+ };
80
+ };
81
+ return workflow({
82
+ name,
83
+ description: `Eval workflow for ${name}`,
84
+ inputSchema: z.object({ datasets: z.array(DatasetSchema) }),
85
+ outputSchema: EvalOutputSchema,
86
+ fn: fn ?? defaultFn
87
+ });
88
+ }
@@ -0,0 +1,13 @@
1
+ export { evalWorkflow } from './eval_workflow.js';
2
+ export type { EvalDefinition, EvalWorkflowConfig, EvalWorkflowInput, EvalWorkflowFn, EvalWorkflowOptions } from './eval_workflow.js';
3
+ export { Verdict } from './verdict.js';
4
+ export { verify } from './verify.js';
5
+ export type { CheckContext } from './verify.js';
6
+ export { judgeVerdict, judgeScore, judgeBoolean, judgeLabel } from './judge.js';
7
+ export type { JudgeArgs } from './judge.js';
8
+ export { interpretResult } from './interpret.js';
9
+ export { aggregateCaseVerdict } from './aggregate.js';
10
+ export { renderEvalOutput, computeExitCode } from './render.js';
11
+ export { getEvalWorkflowName, isEvalWorkflow, getParentWorkflowName } from './naming.js';
12
+ export { VERDICT, CRITICALITY, VerdictSchema, CriticalitySchema, InterpretConfigSchema, EvaluatorResultSchema, EvalCaseSchema, EvalOutputSchema, LastOutputSchema, LastEvalSchema, DatasetSchema } from './schemas.js';
13
+ export type { Verdict as VerdictType, Criticality, InterpretConfig, EvaluatorResult, EvalCase, EvalSummary, EvalOutput, GroundTruth, LastOutput, LastEval, Dataset } from './schemas.js';
package/dist/index.js ADDED
@@ -0,0 +1,9 @@
1
+ export { evalWorkflow } from './eval_workflow.js';
2
+ export { Verdict } from './verdict.js';
3
+ export { verify } from './verify.js';
4
+ export { judgeVerdict, judgeScore, judgeBoolean, judgeLabel } from './judge.js';
5
+ export { interpretResult } from './interpret.js';
6
+ export { aggregateCaseVerdict } from './aggregate.js';
7
+ export { renderEvalOutput, computeExitCode } from './render.js';
8
+ export { getEvalWorkflowName, isEvalWorkflow, getParentWorkflowName } from './naming.js';
9
+ export { VERDICT, CRITICALITY, VerdictSchema, CriticalitySchema, InterpretConfigSchema, EvaluatorResultSchema, EvalCaseSchema, EvalOutputSchema, LastOutputSchema, LastEvalSchema, DatasetSchema } from './schemas.js';
@@ -0,0 +1,16 @@
1
+ export { evalWorkflow } from './eval_workflow.js';
2
+ export type { EvalDefinition, EvalWorkflowConfig, EvalWorkflowInput, EvalWorkflowFn, EvalWorkflowOptions } from './eval_workflow.js';
3
+ export { Verdict } from './verdict.js';
4
+ export { verify } from './verify.js';
5
+ export type { CheckContext } from './verify.js';
6
+ export type { JudgeArgs } from './judge.js';
7
+ export { interpretResult } from './interpret.js';
8
+ export { aggregateCaseVerdict } from './aggregate.js';
9
+ export { renderEvalOutput, computeExitCode } from './render.js';
10
+ export { getEvalWorkflowName, isEvalWorkflow, getParentWorkflowName } from './naming.js';
11
+ export { VERDICT, CRITICALITY, VerdictSchema, CriticalitySchema, InterpretConfigSchema, EvaluatorResultSchema, EvalCaseSchema, EvalOutputSchema, LastOutputSchema, LastEvalSchema, DatasetSchema } from './schemas.js';
12
+ export type { Verdict as VerdictType, Criticality, InterpretConfig, EvaluatorResult, EvalCase, EvalSummary, EvalOutput, GroundTruth, LastOutput, LastEval, Dataset } from './schemas.js';
13
+ export declare const judgeVerdict: (...args: unknown[]) => never;
14
+ export declare const judgeScore: (...args: unknown[]) => never;
15
+ export declare const judgeBoolean: (...args: unknown[]) => never;
16
+ export declare const judgeLabel: (...args: unknown[]) => never;
@@ -0,0 +1,51 @@
1
+ /*
2
+ * HACK: Export workflow-safe function signatures independently.
3
+ *
4
+ * Problem:
5
+ * Eval workflow files pass evaluator functions as config values to evalWorkflow():
6
+ *
7
+ * export default evalWorkflow({ evals: [{ evaluator: evaluateTopic, ... }] });
8
+ *
9
+ * The webpack rewriter (workflow_rewriter/index.mjs) is supposed to strip evaluator
10
+ * imports from the AST via collectTargetImports(), which calls path.remove() on each
11
+ * matched import declaration. However, after collecting imports, the rewriter checks
12
+ * if rewriteFnBodies() performed any rewrites. For eval workflows — which have no
13
+ * fn body, only a config object — rewriteFnBodies() returns false. When that happens,
14
+ * the rewriter returns the original source string unchanged (lines 46-48), discarding
15
+ * the import stripping that collectTargetImports() already applied to the AST.
16
+ *
17
+ * This means webpack follows the full import chain: evaluators.js → @outputai/evals
18
+ * → judge.js → @outputai/llm → node:zlib — which fails because Node.js built-ins
19
+ * can't be bundled into Temporal's deterministic workflow bundle.
20
+ *
21
+ * This file provides an alternative entry point for @outputai/evals that excludes
22
+ * the real judge functions (breaking the chain to @outputai/llm) and replaces them
23
+ * with no-op stubs. The stubs satisfy webpack's named-export resolution. Judge
24
+ * functions are never called inside the workflow bundle — they execute as Temporal
25
+ * activities at runtime where the real entry point (index.js) is used.
26
+ *
27
+ * Remove when:
28
+ * The workflow rewriter in sdk/core/src/worker/webpack_loaders/workflow_rewriter/index.mjs
29
+ * is fixed to generate output from the modified AST even when rewriteFnBodies() returns
30
+ * false — i.e. when collectTargetImports() stripped imports but no fn bodies needed
31
+ * rewriting. This also requires injecting metadata stubs for the stripped evaluator
32
+ * references, since evalWorkflow() calls getMetadata(def.evaluator) at module init time
33
+ * and the identifiers would otherwise be undefined. Once the rewriter properly strips the
34
+ * evaluator → judge → @outputai/llm chain, this file and the "output-workflow-bundle" export
35
+ * condition in package.json can be deleted.
36
+ */
37
+ export { evalWorkflow } from './eval_workflow.js';
38
+ export { Verdict } from './verdict.js';
39
+ export { verify } from './verify.js';
40
+ export { interpretResult } from './interpret.js';
41
+ export { aggregateCaseVerdict } from './aggregate.js';
42
+ export { renderEvalOutput, computeExitCode } from './render.js';
43
+ export { getEvalWorkflowName, isEvalWorkflow, getParentWorkflowName } from './naming.js';
44
+ export { VERDICT, CRITICALITY, VerdictSchema, CriticalitySchema, InterpretConfigSchema, EvaluatorResultSchema, EvalCaseSchema, EvalOutputSchema, LastOutputSchema, LastEvalSchema, DatasetSchema } from './schemas.js';
45
+ const sandboxStub = () => {
46
+ throw new Error('Judge functions are not available in the Temporal workflow bundle');
47
+ };
48
+ export const judgeVerdict = sandboxStub;
49
+ export const judgeScore = sandboxStub;
50
+ export const judgeBoolean = sandboxStub;
51
+ export const judgeLabel = sandboxStub;
@@ -0,0 +1,3 @@
1
+ import type { EvaluationResult } from '@outputai/core';
2
+ import type { InterpretConfig, Verdict } from './schemas.js';
3
+ export declare const interpretResult: (result: EvaluationResult, config: InterpretConfig) => Verdict;
@@ -0,0 +1,40 @@
1
+ import { VERDICT, VerdictSchema } from './schemas.js';
2
+ const VALID_VERDICTS = new Set(VerdictSchema.options);
3
+ const interpretVerdict = (value) => VALID_VERDICTS.has(value) ? value : VERDICT.FAIL;
4
+ const interpretBoolean = (value) => value === true ? VERDICT.PASS : VERDICT.FAIL;
5
+ const interpretNumber = (value, config) => {
6
+ if (typeof value !== 'number' || Number.isNaN(value)) {
7
+ return VERDICT.FAIL;
8
+ }
9
+ if (value >= config.pass) {
10
+ return VERDICT.PASS;
11
+ }
12
+ if (config.partial !== undefined && config.partial !== null && value >= config.partial) {
13
+ return VERDICT.PARTIAL;
14
+ }
15
+ return VERDICT.FAIL;
16
+ };
17
+ const interpretString = (value, config) => {
18
+ if (config.pass.includes(value)) {
19
+ return VERDICT.PASS;
20
+ }
21
+ if (config.partial?.includes(value)) {
22
+ return VERDICT.PARTIAL;
23
+ }
24
+ return VERDICT.FAIL;
25
+ };
26
+ export const interpretResult = (result, config) => {
27
+ const { value } = result;
28
+ switch (config.type) {
29
+ case 'verdict':
30
+ return interpretVerdict(value);
31
+ case 'boolean':
32
+ return interpretBoolean(value);
33
+ case 'number':
34
+ return interpretNumber(value, config);
35
+ case 'string':
36
+ return interpretString(value, config);
37
+ default:
38
+ return VERDICT.FAIL;
39
+ }
40
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,86 @@
1
+ import { describe, it, expect } from 'vitest';
2
+ import { interpretResult } from './interpret.js';
3
+ const makeResult = (value) => ({
4
+ value,
5
+ confidence: 1.0,
6
+ feedback: [],
7
+ dimensions: []
8
+ });
9
+ describe('interpretResult', () => {
10
+ describe('verdict config', () => {
11
+ const config = { type: 'verdict' };
12
+ it('passes through valid verdict values', () => {
13
+ expect(interpretResult(makeResult('pass'), config)).toBe('pass');
14
+ expect(interpretResult(makeResult('partial'), config)).toBe('partial');
15
+ expect(interpretResult(makeResult('fail'), config)).toBe('fail');
16
+ });
17
+ it('returns fail for invalid verdict values', () => {
18
+ expect(interpretResult(makeResult('maybe'), config)).toBe('fail');
19
+ expect(interpretResult(makeResult(''), config)).toBe('fail');
20
+ expect(interpretResult(makeResult(null), config)).toBe('fail');
21
+ expect(interpretResult(makeResult(42), config)).toBe('fail');
22
+ });
23
+ });
24
+ describe('boolean config', () => {
25
+ const config = { type: 'boolean' };
26
+ it('returns pass for true', () => {
27
+ expect(interpretResult(makeResult(true), config)).toBe('pass');
28
+ });
29
+ it('returns fail for false', () => {
30
+ expect(interpretResult(makeResult(false), config)).toBe('fail');
31
+ });
32
+ it('returns fail for truthy non-boolean values', () => {
33
+ expect(interpretResult(makeResult(1), config)).toBe('fail');
34
+ expect(interpretResult(makeResult('true'), config)).toBe('fail');
35
+ });
36
+ });
37
+ describe('number config', () => {
38
+ it('returns pass when value >= pass threshold', () => {
39
+ const config = { type: 'number', pass: 0.8 };
40
+ expect(interpretResult(makeResult(0.9), config)).toBe('pass');
41
+ expect(interpretResult(makeResult(0.8), config)).toBe('pass');
42
+ expect(interpretResult(makeResult(1.0), config)).toBe('pass');
43
+ });
44
+ it('returns fail when value < pass threshold with no partial', () => {
45
+ const config = { type: 'number', pass: 0.8 };
46
+ expect(interpretResult(makeResult(0.7), config)).toBe('fail');
47
+ expect(interpretResult(makeResult(0), config)).toBe('fail');
48
+ });
49
+ it('returns partial when value between partial and pass thresholds', () => {
50
+ const config = { type: 'number', pass: 0.8, partial: 0.5 };
51
+ expect(interpretResult(makeResult(0.6), config)).toBe('partial');
52
+ expect(interpretResult(makeResult(0.5), config)).toBe('partial');
53
+ });
54
+ it('returns fail when value < partial threshold', () => {
55
+ const config = { type: 'number', pass: 0.8, partial: 0.5 };
56
+ expect(interpretResult(makeResult(0.4), config)).toBe('fail');
57
+ });
58
+ it('returns fail for non-number values', () => {
59
+ const config = { type: 'number', pass: 0.8 };
60
+ expect(interpretResult(makeResult(null), config)).toBe('fail');
61
+ expect(interpretResult(makeResult(undefined), config)).toBe('fail');
62
+ expect(interpretResult(makeResult('high'), config)).toBe('fail');
63
+ });
64
+ });
65
+ describe('string config', () => {
66
+ it('returns pass for matching pass values', () => {
67
+ const config = { type: 'string', pass: ['good', 'great'] };
68
+ expect(interpretResult(makeResult('good'), config)).toBe('pass');
69
+ expect(interpretResult(makeResult('great'), config)).toBe('pass');
70
+ });
71
+ it('returns partial for matching partial values', () => {
72
+ const config = { type: 'string', pass: ['good'], partial: ['ok', 'decent'] };
73
+ expect(interpretResult(makeResult('ok'), config)).toBe('partial');
74
+ expect(interpretResult(makeResult('decent'), config)).toBe('partial');
75
+ });
76
+ it('returns fail for non-matching values', () => {
77
+ const config = { type: 'string', pass: ['good'], partial: ['ok'] };
78
+ expect(interpretResult(makeResult('bad'), config)).toBe('fail');
79
+ expect(interpretResult(makeResult(''), config)).toBe('fail');
80
+ });
81
+ it('returns fail when no partial config and value not in pass', () => {
82
+ const config = { type: 'string', pass: ['good'] };
83
+ expect(interpretResult(makeResult('ok'), config)).toBe('fail');
84
+ });
85
+ });
86
+ });
@@ -0,0 +1,10 @@
1
+ import { EvaluationVerdictResult, EvaluationNumberResult, EvaluationBooleanResult, EvaluationStringResult, z } from '@outputai/core';
2
+ export type JudgeArgs = {
3
+ prompt: string;
4
+ variables?: Record<string, string | number | boolean>;
5
+ schema?: z.ZodType;
6
+ };
7
+ export declare function judgeVerdict({ prompt, variables, schema }: JudgeArgs): Promise<EvaluationVerdictResult>;
8
+ export declare function judgeScore({ prompt, variables, schema }: JudgeArgs): Promise<EvaluationNumberResult>;
9
+ export declare function judgeBoolean({ prompt, variables, schema }: JudgeArgs): Promise<EvaluationBooleanResult>;
10
+ export declare function judgeLabel({ prompt, variables, schema }: JudgeArgs): Promise<EvaluationStringResult>;