🪢 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(ingestion): store unsupported modelParameters values as JSON strings (#19146)
Hassieb Pakzad6af0b026aa63
diff --git a/packages/shared/src/server/ingestion/types.ts b/packages/shared/src/server/ingestion/types.tsindex 72e0cb3aab..4b4a796135 100644--- a/packages/shared/src/server/ingestion/types.ts+++ b/packages/shared/src/server/ingestion/types.ts@@ -464,6 +464,25 @@ export const SdkLogEvent = z.object({// With this setup parsing should be more lightweight and doesn't block other requests.// As we allow plain values, arrays, and objects the JSON parse via bodyParser should suffice.+// Values outside the supported shapes (e.g. a structured-output+// `response_format`) are stored as JSON strings instead of rejecting the whole+// generation. OTel ingestion applies the same rule before reaching this schema.+const ModelParameters = z+ .record(+ z.string(),+ z+ .union([+ z.string(),+ z.number(),+ z.boolean(),+ z.array(z.string()),+ z.record(z.string(), z.string()),+ z.unknown().transform((value) => JSON.stringify(value)),+ ])+ .nullish(),+ )+ .nullish();+// Complete schema factory - single source of truth for ALL schemasconst createAllIngestionSchemas = ({isPublic = true,@@ -526,20 +545,7 @@ const createAllIngestionSchemas = ({const CreateGenerationBody = CreateSpanBody.extend({completionStartTime: stringDateTime,model: z.string().nullish(),- modelParameters: z- .record(- z.string(),- z- .union([- z.string(),- z.number(),- z.boolean(),- z.array(z.string()),- z.record(z.string(), z.string()),- ])- .nullish(),- )- .nullish(),+ modelParameters: ModelParameters,usage: usage,usageDetails: UsageDetails,costDetails: CostDetails,@@ -555,20 +561,7 @@ const createAllIngestionSchemas = ({const UpdateGenerationBody = UpdateSpanBody.extend({completionStartTime: stringDateTime,model: z.string().nullish(),- modelParameters: z- .record(- z.string(),- z- .union([- z.string(),- z.number(),- z.boolean(),- z.array(z.string()),- z.record(z.string(), z.string()),- ])- .nullish(),- )- .nullish(),+ modelParameters: ModelParameters,usage: usage,usageDetails: UsageDetails,costDetails: CostDetails,diff --git a/web/src/__tests__/server/ingestion-api.servertest.ts b/web/src/__tests__/server/ingestion-api.servertest.tsindex 7fc8f0b7d7..214c49bb3e 100644--- a/web/src/__tests__/server/ingestion-api.servertest.ts+++ b/web/src/__tests__/server/ingestion-api.servertest.ts@@ -27,6 +27,53 @@ describe("ingestion timestamp compatibility", () => {);});+describe("ingestion modelParameters compatibility", () => {+ const parseModelParameters = (modelParameters: Record<string, unknown>) =>+ ingestionEvent.parse({+ id: "event-id",+ type: "generation-create",+ timestamp: new Date().toISOString(),+ body: { id: "generation-id", modelParameters },+ }).body;++ it("keeps supported values unchanged", () => {+ const modelParameters = {+ temperature: 0.2,+ stream: false,+ stop: ["\n"],+ reasoning: { effort: "high" },+ seed: null,+ };++ expect(parseModelParameters(modelParameters)).toMatchObject({+ modelParameters,+ });+ });++ it("serializes nested values instead of rejecting the generation", () => {+ const responseFormat = {+ type: "json_schema",+ json_schema: { name: "answer", strict: true, schema: { type: "object" } },+ };++ expect(+ parseModelParameters({+ temperature: 0,+ response_format: responseFormat,+ thinking: { type: "enabled", budget_tokens: 1024 },+ stop_token_ids: [1, 2],+ }),+ ).toMatchObject({+ modelParameters: {+ temperature: 0,+ response_format: JSON.stringify(responseFormat),+ thinking: '{"type":"enabled","budget_tokens":1024}',+ stop_token_ids: "[1,2]",+ },+ });+ });+});+let projectId: string;let auth: string;let publicKey: string;