🪢 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(datasets): fix errors during json schema generation (#13193)
Tobias Wochinger8834a3af42e8
diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex cd0bdcdb4b..00ad8118c5 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -63,7 +63,7 @@ importers:version: 16.2.3(@babel/[email protected])(@opentelemetry/[email protected])(@playwright/[email protected])([email protected])([email protected]([email protected]))([email protected])next-auth:specifier: ^4.24.13- version: 4.24.13(patch_hash=7b301d2607ee3cd8bba4f6978ba8cdd7a616b59d6e414191da3b38950ce08e66)([email protected](@babel/[email protected])(@opentelemetry/[email protected])(@playwright/[email protected])([email protected])([email protected]([email protected]))([email protected]))([email protected])([email protected]([email protected]))([email protected])+ version: 4.24.13(patch_hash=7b301d2607ee3cd8bba4f6978ba8cdd7a616b59d6e414191da3b38950ce08e66)([email protected](@opentelemetry/[email protected])(@playwright/[email protected])([email protected]([email protected]))([email protected]))([email protected])([email protected]([email protected]))([email protected])zod:specifier: 4.3.6version: 4.3.6@@ -246,7 +246,7 @@ importers:version: 11.2.7next-auth:specifier: ^4.24.13- version: 4.24.13(patch_hash=7b301d2607ee3cd8bba4f6978ba8cdd7a616b59d6e414191da3b38950ce08e66)([email protected](@babel/[email protected])(@opentelemetry/[email protected])(@playwright/[email protected])([email protected])([email protected]([email protected]))([email protected]))([email protected])([email protected]([email protected]))([email protected])+ version: 4.24.13(patch_hash=7b301d2607ee3cd8bba4f6978ba8cdd7a616b59d6e414191da3b38950ce08e66)([email protected](@opentelemetry/[email protected])(@playwright/[email protected])([email protected]([email protected]))([email protected]))([email protected])([email protected]([email protected]))([email protected])nodemailer:specifier: ^7.0.11version: 7.0.11@@ -606,8 +606,8 @@ importers:specifier: ^9.0.5version: 9.0.5json-schema-faker:- specifier: ^0.5.9- version: 0.5.9+ specifier: 0.6.1+ version: 0.6.1langchain:specifier: ^1.3.0version: 1.3.0(@langchain/[email protected](@opentelemetry/[email protected])(@opentelemetry/[email protected](@opentelemetry/[email protected]))(@opentelemetry/[email protected](@opentelemetry/[email protected]))([email protected]([email protected])([email protected]))([email protected]))(@opentelemetry/[email protected])(@opentelemetry/[email protected](@opentelemetry/[email protected]))(@opentelemetry/[email protected](@opentelemetry/[email protected]))([email protected]([email protected])([email protected]))([email protected]([email protected]))([email protected])([email protected])([email protected]([email protected]))@@ -628,7 +628,7 @@ importers:version: 16.2.3(@babel/[email protected])(@opentelemetry/[email protected])(@playwright/[email protected])([email protected])([email protected]([email protected]))([email protected])next-auth:specifier: ^4.24.13- version: 4.24.13(patch_hash=7b301d2607ee3cd8bba4f6978ba8cdd7a616b59d6e414191da3b38950ce08e66)([email protected](@babel/[email protected])(@opentelemetry/[email protected])(@playwright/[email protected])([email protected])([email protected]([email protected]))([email protected]))([email protected])([email protected]([email protected]))([email protected])+ version: 4.24.13(patch_hash=7b301d2607ee3cd8bba4f6978ba8cdd7a616b59d6e414191da3b38950ce08e66)([email protected](@opentelemetry/[email protected])(@playwright/[email protected])([email protected]([email protected]))([email protected]))([email protected])([email protected]([email protected]))([email protected])next-query-params:specifier: ^5.1.0version: 5.1.0([email protected](@babel/[email protected])(@opentelemetry/[email protected])(@playwright/[email protected])([email protected])([email protected]([email protected]))([email protected]))([email protected])([email protected]([email protected]([email protected]))([email protected]))@@ -5930,9 +5930,6 @@ packages:resolution: {integrity: sha512-+ys997U96po4Kx/ABpBCqhA9EuxJaQWDQg7295H4hBphv3IZg0boBKuwYpt4YXp6MZ5AmZQnU/tyMTlRpaSejg==}engines: {node: '>= 0.4'}- resolution: {integrity: sha512-HpX65o1Hnr9HH25ojC1YGs7HCQLq0GCOibSaWER0eNpgJ/Z1MZv2mTc7+xh6WOPxbRVcmgbv4hGU+uSQ/2xFZQ==}-resolution: {integrity: sha512-P8BjAsXvZS+VIDUI11hHCQEv74YT67YUi5JJFNWIqL235sBmjX4+qx9Muvls5ivyNENctx46xQLQ3aTuE7ssaQ==}engines: {node: '>=6'}@@ -7043,9 +7040,6 @@ packages:resolution: {integrity: sha512-8RipRLol37bNs2bhoV67fiTEvdTrbMUYcFTiy3+wuuOnUog2QBHCZWXDRijWQfAkhBj2Uf5UnVaiWwA5vdd82w==}engines: {node: '>= 6'}- resolution: {integrity: sha512-varLbTj0e0yVyRpqQhuWV+8hlePAgaoFRhNFj50BNjEIrw1/DphHSObtqwskVCPWNgzwPoQrZAbfa/SBiicNeg==}-resolution: {integrity: sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==}engines: {node: '>=12.20.0'}@@ -7922,14 +7916,10 @@ packages:resolution: {integrity: sha512-xyFwyhro/JEof6Ghe2iz2NcXoj2sloNsWr/XsERDK/oiPCfaNhl5ONfp+jQdAZRQQ0IJWNzH9zIZF7li91kh2w==}- resolution: {integrity: sha512-fNKLHgDvfGNNTX1zqIjqFMJjCLzJ2kvnJ831x4aqkAoeE4jE2TxvpJdhOnk3JU3s42vFzmXvkpbYzH5H3ncAzg==}+ resolution: {integrity: sha512-IMF9QGFn/j7sys1LxgYpt/+0LUozFE8R/yUav4D7NqsHnh5L0mbJZOiU724nlJ3g+ZZo6NykVtTeJLoVcOP6Xw==}hasBin: true- resolution: {integrity: sha512-pXe9H1m6IgIpXmE5JSb8epilNTGsmTb2iPohAXpOdhqGFbQjNeHHsZxU+C8w6T81GZxSPFLeUoqDJmzxx5IGuw==}- deprecated: Please switch to @apidevtools/json-schema-ref-parser-resolution: {integrity: sha512-+DWg8jCJG2TEnpy7kOm/7/AxaYoaRbjVB4LFZLySZlWn8exGs3A4OLJR966cVvU26N7X9TWxl+Jsw7dzAqKT6g==}engines: {node: '>=16'}@@ -8827,9 +8817,6 @@ packages:resolution: {integrity: sha512-VXJjc87FScF88uafS3JllDgvAm+c/Slfz06lorj2uAY34rlUu0Nt+v8wreiImcrgAjjIHp1rXpTDlLOGw29WwQ==}engines: {node: '>=18'}- resolution: {integrity: sha512-jQ31cORBFE6td25deYeD80wxKBMj+zBmHTrVxnc6CKhx8gho6ipmWM5zj/oeoqioZ99yqBls9Z/9Nss7J26G2g==}-resolution: {integrity: sha512-YgBpdJHPyQ2UE5x+hlSXcnejzAvD0b22U2OuAP+8OnlJT+PjWPxtgmGqKKc+RgTM63U9gN0YzrYc71R2WT/hTA==}engines: {node: '>=18'}@@ -13199,7 +13186,7 @@ snapshots:'@next-auth/[email protected](@prisma/[email protected]([email protected]([email protected])([email protected]))([email protected]))([email protected](patch_hash=7b301d2607ee3cd8bba4f6978ba8cdd7a616b59d6e414191da3b38950ce08e66)([email protected](@babel/[email protected])(@opentelemetry/[email protected])(@playwright/[email protected])([email protected])([email protected]([email protected]))([email protected]))([email protected])([email protected]([email protected]))([email protected]))':dependencies:'@prisma/client': 6.19.3([email protected]([email protected])([email protected]))([email protected])- next-auth: 4.24.13(patch_hash=7b301d2607ee3cd8bba4f6978ba8cdd7a616b59d6e414191da3b38950ce08e66)([email protected](@babel/[email protected])(@opentelemetry/[email protected])(@playwright/[email protected])([email protected])([email protected]([email protected]))([email protected]))([email protected])([email protected]([email protected]))([email protected])+ next-auth: 4.24.13(patch_hash=7b301d2607ee3cd8bba4f6978ba8cdd7a616b59d6e414191da3b38950ce08e66)([email protected](@opentelemetry/[email protected])(@playwright/[email protected])([email protected]([email protected]))([email protected]))([email protected])([email protected]([email protected]))([email protected])'@next/[email protected]': {}@@ -16784,8 +16771,6 @@ snapshots:call-bind-apply-helpers: 1.0.2get-intrinsic: 1.3.0- [email protected]: {}-@@ -17606,7 +17591,7 @@ snapshots:tinyglobby: 0.2.15unrs-resolver: 1.11.1optionalDependencies:- eslint-plugin-import: 2.32.0(@typescript-eslint/[email protected]([email protected]([email protected]))([email protected]))([email protected])([email protected]([email protected]))transitivePeerDependencies:- supports-color@@ -18103,8 +18088,6 @@ snapshots:hasown: 2.0.2mime-types: 2.1.35- [email protected]: {}-dependencies:fetch-blob: 3.2.0@@ -19258,16 +19241,7 @@ snapshots:- dependencies:- json-schema-ref-parser: 6.1.0- jsonpath-plus: 10.3.0-- dependencies:- call-me-maybe: 1.0.2- js-yaml: 3.14.2- ono: 4.0.11+ [email protected]: {}dependencies:@@ -20135,7 +20109,7 @@ snapshots:dependencies:type-fest: 2.19.0- [email protected](patch_hash=7b301d2607ee3cd8bba4f6978ba8cdd7a616b59d6e414191da3b38950ce08e66)([email protected](@babel/[email protected])(@opentelemetry/[email protected])(@playwright/[email protected])([email protected])([email protected]([email protected]))([email protected]))([email protected])([email protected]([email protected]))([email protected]):+ [email protected](patch_hash=7b301d2607ee3cd8bba4f6978ba8cdd7a616b59d6e414191da3b38950ce08e66)([email protected](@opentelemetry/[email protected])(@playwright/[email protected])([email protected]([email protected]))([email protected]))([email protected])([email protected]([email protected]))([email protected]):dependencies:'@babel/runtime': 7.29.2'@panva/hkdf': 1.2.1@@ -20385,10 +20359,6 @@ snapshots:dependencies:mimic-function: 5.0.1- dependencies:- format-util: 1.0.5-dependencies:default-browser: 5.5.0diff --git a/web/jest.config.mjs b/web/jest.config.mjsindex 2d01136854..6382019ff7 100644--- a/web/jest.config.mjs+++ b/web/jest.config.mjs@@ -35,7 +35,28 @@ const endToEndServerTestConfig = {// To avoid the "Cannot use import statement outside a module" errors while transforming ESM.// jsonpath-plus is needed because @langfuse/shared barrel exports evals/utilities which imports it-const esModules = ["superjson", "jsonpath-plus"];+const esModules = ["superjson", "jsonpath-plus", "json-schema-faker"];++// ESM-only packages need explicit resolution to bypass Jest's CJS exports-map resolver+const esmOnlyModuleNameMapper = {+ "^json-schema-faker$":+ "<rootDir>/node_modules/json-schema-faker/dist/index.js",+};++const transformIgnorePatterns = [+ `/web/node_modules/(?!(${esModules.join("|")})/)`,+];++// Helper to merge our ESM moduleNameMapper with Next.js's built-in mappings+const withEsmMapper = (/** @type {import('jest').Config} */ resolved) => ({+ ...resolved,+ transformIgnorePatterns,+ moduleNameMapper: {+ ...resolved.moduleNameMapper,+ ...esmOnlyModuleNameMapper,+ },+});+// Add any custom config to be passed to Jest/** @type {import('jest').Config} */const config = {@@ -45,26 +66,11 @@ const config = {workerIdleMemoryLimit: "512MB",// Add more setup options before each test is runprojects: [- {- ...(await createJestConfig(clientTestConfig)()),- // Added transformIgnorePatterns to client tests to handle ESM dependencies from @langfuse/shared- // Without this, importing from @langfuse/shared fails with "Unexpected token 'export'" errors- transformIgnorePatterns: [- `/web/node_modules/(?!(${esModules.join("|")})/)`,- ],- },- {- ...(await createJestConfig(serverTestConfig)()),- transformIgnorePatterns: [- `/web/node_modules/(?!(${esModules.join("|")})/)`,- ],- },- {- ...(await createJestConfig(endToEndServerTestConfig)()),- transformIgnorePatterns: [- `/web/node_modules/(?!(${esModules.join("|")})/)`,- ],- },+ // Added transformIgnorePatterns to handle ESM dependencies from @langfuse/shared+ // Without this, importing from @langfuse/shared fails with "Unexpected token 'export'" errors+ withEsmMapper(await createJestConfig(clientTestConfig)()),+ withEsmMapper(await createJestConfig(serverTestConfig)()),+ withEsmMapper(await createJestConfig(endToEndServerTestConfig)()),],};diff --git a/web/package.json b/web/package.jsonindex 9ac7ec287b..d16d003382 100644--- a/web/package.json+++ b/web/package.json@@ -121,7 +121,7 @@"https-proxy-agent": "^7.0.6","ioredis": "^5.8.2","ip-address": "^9.0.5",- "json-schema-faker": "^0.5.9",+ "json-schema-faker": "0.6.1","langchain": "^1.3.0","langfuse": "3.38.4","lodash": "^4.18.1",diff --git a/web/src/features/datasets/components/DatasetSchemaHoverCard.tsx b/web/src/features/datasets/components/DatasetSchemaHoverCard.tsxindex 6ee8c83441..41d2af4a8a 100644--- a/web/src/features/datasets/components/DatasetSchemaHoverCard.tsx+++ b/web/src/features/datasets/components/DatasetSchemaHoverCard.tsx@@ -8,7 +8,7 @@ import { CodeMirrorEditor } from "@/src/components/editor";import type { Prisma } from "@langfuse/shared";import { Button } from "@/src/components/ui/button";import { Separator } from "@/src/components/ui/separator";-import { useMemo, useState } from "react";+import { useEffect, useState } from "react";import { generateSchemaExample } from "../lib/generateSchemaExample";import { copyTextToClipboard } from "@/src/utils/clipboard";@@ -29,7 +29,16 @@ export const DatasetSchemaHoverCard: React.FC<DatasetSchemaHoverCardProps> = ({const schemaString = JSON.stringify(schema, null, 2);// Generate example object from schema- const exampleObject = useMemo(() => generateSchemaExample(schema), [schema]);+ const [exampleObject, setExampleObject] = useState("");+ useEffect(() => {+ let cancelled = false;+ void generateSchemaExample(schema).then((result) => {+ if (!cancelled) setExampleObject(result);+ });+ return () => {+ cancelled = true;+ };+ }, [schema]);// State for copy button feedbackconst [copied, setCopied] = useState(false);diff --git a/web/src/features/datasets/components/NewDatasetItemForm.tsx b/web/src/features/datasets/components/NewDatasetItemForm.tsxindex 2ca6ad5a8e..b2961524eb 100644--- a/web/src/features/datasets/components/NewDatasetItemForm.tsx+++ b/web/src/features/datasets/components/NewDatasetItemForm.tsx@@ -179,36 +179,40 @@ export const NewDatasetItemForm = (props: {const dataset = selectedDatasets[0];if (!dataset) return;+ let cancelled = false;+// Generate input placeholder if schema exists and field is empty- if (dataset.inputSchema && !inputValue) {- const placeholder = generateSchemaExample(dataset.inputSchema);- if (placeholder) {- form.setValue("input", placeholder, {- shouldValidate: false,- shouldDirty: false,- shouldTouch: false,- });- }+ if (dataset.inputSchema && !form.getValues("input")) {+ void generateSchemaExample(dataset.inputSchema).then((placeholder) => {+ if (!cancelled && placeholder && !form.getValues("input")) {+ form.setValue("input", placeholder, {+ shouldValidate: false,+ shouldDirty: false,+ shouldTouch: false,+ });+ }+ });}// Generate expectedOutput placeholder if schema exists and field is empty- if (dataset.expectedOutputSchema && !expectedOutputValue) {- const placeholder = generateSchemaExample(dataset.expectedOutputSchema);- if (placeholder) {- form.setValue("expectedOutput", placeholder, {- shouldValidate: false,- shouldDirty: false,- shouldTouch: false,- });- }+ if (dataset.expectedOutputSchema && !form.getValues("expectedOutput")) {+ void generateSchemaExample(dataset.expectedOutputSchema).then(+ (placeholder) => {+ if (!cancelled && placeholder && !form.getValues("expectedOutput")) {+ form.setValue("expectedOutput", placeholder, {+ shouldValidate: false,+ shouldDirty: false,+ shouldTouch: false,+ });+ }+ },+ );}- }, [- selectedDatasets,- hasInitialValues,- inputValue,- expectedOutputValue,- form,- ]);++ return () => {+ cancelled = true;+ };+ }, [selectedDatasets, hasInitialValues, form]);const utils = api.useUtils();const createManyDatasetItemsMutation =diff --git a/web/src/features/datasets/lib/generateSchemaExample.clienttest.ts b/web/src/features/datasets/lib/generateSchemaExample.clienttest.tsnew file mode 100644index 0000000000..8be1cdcbe9--- /dev/null+++ b/web/src/features/datasets/lib/generateSchemaExample.clienttest.ts@@ -0,0 +1,53 @@+import { generateSchemaExample } from "./generateSchemaExample";++describe("generateSchemaExample", () => {+ it("generates example for a simple object schema", async () => {+ const schema = {+ type: "object",+ properties: {+ name: { type: "string" },+ age: { type: "number" },+ },+ };+ const result = await generateSchemaExample(schema);+ expect(result).not.toBe("");+ const parsed = JSON.parse(result);+ expect(parsed).toHaveProperty("name");+ expect(parsed).toHaveProperty("age");+ });++ it("handles array type without items property", async () => {+ const schema = {+ type: "object",+ properties: {+ structure: { type: "array" },+ },+ };+ const result = await generateSchemaExample(schema);+ expect(result).not.toBe("");+ });++ it("preserves array items when they exist", async () => {+ const schema = {+ type: "object",+ properties: {+ tags: {+ type: "array",+ items: { type: "string" },+ },+ },+ };+ const result = await generateSchemaExample(schema);+ expect(result).not.toBe("");+ const parsed = JSON.parse(result);+ expect(Array.isArray(parsed.tags)).toBe(true);+ });++ it("returns empty string for null schema", async () => {+ expect(await generateSchemaExample(null)).toBe("");+ });++ it("returns empty string for non-object schema", async () => {+ expect(await generateSchemaExample("not an object")).toBe("");+ });+});diff --git a/web/src/features/datasets/lib/generateSchemaExample.ts b/web/src/features/datasets/lib/generateSchemaExample.tsindex f329a97f88..70c27495a8 100644--- a/web/src/features/datasets/lib/generateSchemaExample.ts+++ b/web/src/features/datasets/lib/generateSchemaExample.ts@@ -1,4 +1,4 @@-import jsf from "json-schema-faker";+import { generateJson, type JsonSchema } from "json-schema-faker";import type { Prisma } from "@langfuse/shared";/**@@ -6,24 +6,22 @@ import type { Prisma } from "@langfuse/shared";* @param schema - JSON Schema to generate example from* @returns Formatted JSON string of the generated example, or empty string on error*/-export function generateSchemaExample(schema: Prisma.JsonValue): string {+export async function generateSchemaExample(+ schema: Prisma.JsonValue,+): Promise<string> {try {if (!schema || typeof schema !== "object") {- console.error("Invalid schema: must be an object", schema);-return "";}- jsf.option({++ return await generateJson(schema as JsonSchema, {alwaysFakeOptionals: true,useDefaultValue: true,useExamplesValue: true,+ pretty: true,});-- const generated = jsf.generate(schema);-- return JSON.stringify(generated, null, 2);} catch (error) {- console.error("Failed to generate schema example:", error);+ console.warn("Failed to generate schema example:", error);return "";}