🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
fix(evals): validate default model structured output (#15888)
Hassieb Pakzad48a8245b8a52
diff --git a/packages/shared/src/server/llm/testModelCall.test.ts b/packages/shared/src/server/llm/testModelCall.test.tsnew file mode 100644index 0000000000..21d574c460--- /dev/null+++ b/packages/shared/src/server/llm/testModelCall.test.ts@@ -0,0 +1,57 @@+import { createOpenAI } from "@ai-sdk/openai";+import { MockLanguageModelV4 } from "ai/test";+import { describe, expect, it, vi } from "vitest";++import { encrypt } from "../../encryption";+import { testModelCall } from "./testModelCall";+import { LLMAdapter } from "./types";++vi.mock("@ai-sdk/openai", () => ({ createOpenAI: vi.fn() }));++describe("testModelCall", () => {+ it("rejects when the model produces no structured output", async () => {+ vi.mocked(createOpenAI).mockReturnValue({+ chat: () =>+ new MockLanguageModelV4({+ doGenerate: {+ content: [],+ finishReason: { unified: "length", raw: "length" },+ usage: {+ inputTokens: {+ total: 1,+ noCache: 1,+ cacheRead: undefined,+ cacheWrite: undefined,+ },+ outputTokens: { total: 1, text: 0, reasoning: 1 },+ },+ warnings: [],+ },+ }),+ responses: vi.fn(),+ } as never);++ await expect(+ testModelCall({+ provider: "openai",+ model: "reasoning-model",+ apiKey: {+ id: "api-key-id",+ projectId: "project-id",+ createdAt: new Date(),+ updatedAt: new Date(),+ adapter: LLMAdapter.OpenAI,+ provider: "openai",+ displaySecretKey: "sk-...test",+ secretKey: encrypt("sk-test"),+ extraHeaders: null,+ extraHeaderKeys: [],+ baseURL: null,+ customModels: [],+ withDefaultModels: true,+ config: null,+ },+ }),+ ).rejects.toMatchObject({ name: "AI_NoOutputGeneratedError" });+ });+});diff --git a/packages/shared/src/server/llm/testModelCall.ts b/packages/shared/src/server/llm/testModelCall.tsindex f908c8ce81..adff7165bb 100644--- a/packages/shared/src/server/llm/testModelCall.ts+++ b/packages/shared/src/server/llm/testModelCall.ts@@ -36,7 +36,7 @@ export const testModelCall = async ({reasoning: z.string(),});- await generateLLMText({+ const result = await generateLLMText({...mapLegacyLLMCompletionParams({connection: apiKey,messages: [@@ -57,4 +57,7 @@ export const testModelCall = async ({output: createLLMOutput(schema),timeout,});++ // Accessing output makes the AI SDK validate that structured output exists.+ const { output: _output } = result;};