Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix(dataset-run-item): enhance metadata conversion to handle various data types (#9684)

marliessophie90fc4c3a378d
diff --git a/worker/src/features/experiments/experimentServiceClickhouse.ts b/worker/src/features/experiments/experimentServiceClickhouse.ts
index e11b079747..3c1d42f6bc 100644
--- a/worker/src/features/experiments/experimentServiceClickhouse.ts
+++ b/worker/src/features/experiments/experimentServiceClickhouse.ts
@@ -78,8 +78,6 @@ async function processItem(
traceId: newTraceId,
observationId: null,
error: null,
- input: datasetItem.input,
- expectedOutput: datasetItem.expectedOutput,
createdAt: timestamp,
datasetId: datasetItem.datasetId,
runId: config.runId,
diff --git a/worker/src/services/IngestionService/utils.ts b/worker/src/services/IngestionService/utils.ts
index 983781603d..61f5ef09be 100644
--- a/worker/src/services/IngestionService/utils.ts
+++ b/worker/src/services/IngestionService/utils.ts
@@ -26,21 +26,31 @@ export const convertJsonSchemaToRecord = (
export const convertPostgresJsonToMetadataRecord = (
metadata: Prisma.JsonValue,
): Record<string, string> => {
- return typeof metadata === "string"
- ? { metadata: metadata }
- : Array.isArray(metadata)
- ? { metadata: JSON.stringify(metadata) }
- : (metadata as Record<string, string>);
+ if (
+ typeof metadata === "string" ||
+ typeof metadata === "number" ||
+ typeof metadata === "boolean"
+ ) {
+ return { metadata: String(metadata) };
+ }
+ if (Array.isArray(metadata)) {
+ return { metadata: JSON.stringify(metadata) };
+ }
+ if (metadata && typeof metadata === "object") {
+ return convertRecordValuesToString(metadata as Record<string, unknown>);
+ }
+ return {};
};
export const convertRecordValuesToString = (
record: Record<string, unknown>,
): Record<string, string> => {
+ const result: Record<string, string> = {};
for (const key in record) {
const value = record[key];
- record[key] = typeof value === "string" ? value : JSON.stringify(value);
+ result[key] = typeof value === "string" ? value : JSON.stringify(value);
}
- return record as Record<string, string>;
+ return result;
};
export function overwriteObject(