Skip to content

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

fix(v4-add-to-dataset): Allow non-string JSON prefill values for new dataset items (#13053)

marliessophie0cf2a33473bf
diff --git a/web/src/features/datasets/components/NewDatasetItemFromExistingObject.tsx b/web/src/features/datasets/components/NewDatasetItemFromExistingObject.tsx
index 3f66585f2b..5f7fa4604f 100644
--- a/web/src/features/datasets/components/NewDatasetItemFromExistingObject.tsx
+++ b/web/src/features/datasets/components/NewDatasetItemFromExistingObject.tsx
@@ -24,6 +24,7 @@ import { useIsAuthenticatedAndProjectMember } from "@/src/features/auth/hooks";
import { parseJsonPrioritised } from "@langfuse/shared";
import { ActionButton } from "@/src/components/ActionButton";
import { type MetadataDomainClient } from "@/src/utils/clientSideDomainTypes";
+import { type Prisma } from "@langfuse/shared";
/**
* Component for creating a new dataset item from an existing object.
@@ -39,22 +40,30 @@ export const NewDatasetItemFromExistingObject = (props: {
traceId?: string;
observationId?: string;
fromDatasetId?: string;
- input: string | null;
- output: string | null;
+ input: Prisma.JsonValue | null;
+ output: Prisma.JsonValue | null;
metadata: MetadataDomainClient;
isCopyItem?: boolean;
buttonVariant?: ButtonProps["variant"];
size?: ButtonProps["size"];
}) => {
- const parsedInput =
- props.input && typeof props.input === "string"
- ? (parseJsonPrioritised(props.input) ?? null)
- : null;
+ const normalizePrefillValue = (
+ value: Prisma.JsonValue | null,
+ ): Prisma.JsonValue | null => {
+ if (value === null || value === undefined) {
+ return null;
+ }
- const parsedOutput =
- props.output && typeof props.output === "string"
- ? (parseJsonPrioritised(props.output) ?? null)
- : null;
+ if (typeof value === "string") {
+ const parsed = parseJsonPrioritised(value);
+ return parsed !== undefined ? parsed : value;
+ }
+
+ return value;
+ };
+
+ const parsedInput = normalizePrefillValue(props.input);
+ const parsedOutput = normalizePrefillValue(props.output);
const [isFormOpen, setIsFormOpen] = useState(false);
const isAuthenticatedAndProjectMember = useIsAuthenticatedAndProjectMember(