Skip to content

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

fix(prompts): enforce name length and metrics request limits (#18646)

tobi_kl5b9cc4834879
diff --git a/fern/apis/server/definition/prompts.yml b/fern/apis/server/definition/prompts.yml
index df3d3c6606..086a6a1abd 100644
--- a/fern/apis/server/definition/prompts.yml
+++ b/fern/apis/server/definition/prompts.yml
@@ -137,7 +137,9 @@ types:
CreateChatPromptRequest:
properties:
- name: string
+ name:
+ type: string
+ docs: The full prompt name, including any folder path, with at most 255 characters.
prompt: list<ChatMessageWithPlaceholders>
config: optional<unknown>
type: CreateChatPromptType
@@ -153,7 +155,9 @@ types:
CreateTextPromptRequest:
properties:
- name: string
+ name:
+ type: string
+ docs: The full prompt name, including any folder path, with at most 255 characters.
prompt: string
config: optional<unknown>
type: optional<CreateTextPromptType>
diff --git a/web/public/generated/api/openapi.yml b/web/public/generated/api/openapi.yml
index ecc4f56865..337a689776 100644
--- a/web/public/generated/api/openapi.yml
+++ b/web/public/generated/api/openapi.yml
@@ -15935,6 +15935,9 @@ components:
properties:
name:
type: string
+ description: >-
+ The full prompt name, including any folder path, with at most 255
+ characters.
prompt:
type: array
items:
@@ -15969,6 +15972,9 @@ components:
properties:
name:
type: string
+ description: >-
+ The full prompt name, including any folder path, with at most 255
+ characters.
prompt:
type: string
config:
diff --git a/web/src/features/prompts/server/actions/createPrompt.ts b/web/src/features/prompts/server/actions/createPrompt.ts
index 6ae2a90344..8d14d52772 100644
--- a/web/src/features/prompts/server/actions/createPrompt.ts
+++ b/web/src/features/prompts/server/actions/createPrompt.ts
@@ -8,6 +8,7 @@ import {
type Prompt,
type CreatePromptTRPCType,
LATEST_PROMPT_LABEL,
+ PROMPT_NAME_MAX_LENGTH,
PromptType,
extractVariables,
} from "@langfuse/shared";
@@ -108,6 +109,12 @@ export const createPrompt = async ({
orderBy: [{ version: "desc" }],
});
+ if (!latestPrompt && name.length > PROMPT_NAME_MAX_LENGTH) {
+ throw new InvalidRequestError(
+ `Prompt name must be at most ${PROMPT_NAME_MAX_LENGTH} characters`,
+ );
+ }
+
if (latestPrompt && latestPrompt.type !== type) {
throw new InvalidRequestError(
"Previous versions have different prompt type. Create a new prompt with a different name.",
@@ -298,6 +305,12 @@ export const duplicatePrompt = async ({
prisma,
user,
}: DuplicatePromptParams) => {
+ if (name.length > PROMPT_NAME_MAX_LENGTH) {
+ throw new InvalidRequestError(
+ `Prompt name must be at most ${PROMPT_NAME_MAX_LENGTH} characters`,
+ );
+ }
+
// validate that name is unique in project, uniqueness constraint too permissive as it includes version
const promptNameExists = await prisma.prompt.findFirst({
where: {
@@ -540,6 +553,12 @@ export const duplicateFolder = async ({
duplicatedPromptNames.get(originalName) ??
`${targetPath}${originalName.slice(sourcePath.length)}`;
+ if (newName.length > PROMPT_NAME_MAX_LENGTH) {
+ throw new InvalidRequestError(
+ `Prompt name must be at most ${PROMPT_NAME_MAX_LENGTH} characters`,
+ );
+ }
+
const promptsToCopy = isSingleVersion ? [latestVersion] : versions;
for (const prompt of promptsToCopy) {
diff --git a/web/src/features/prompts/server/routers/promptRouter.ts b/web/src/features/prompts/server/routers/promptRouter.ts
index 0615b8f317..52e2f8f1cd 100644
--- a/web/src/features/prompts/server/routers/promptRouter.ts
+++ b/web/src/features/prompts/server/routers/promptRouter.ts
@@ -267,7 +267,8 @@ export const promptRouter = createTRPCRouter({
z
.object({
projectId: z.string(),
- promptNames: z.array(z.string()),
+ // Allow longer legacy names when fetching metrics; new names are limited to 255 characters.
+ promptNames: z.array(z.string().max(1500)).max(50),
...promptMetricsTimeWindow,
})
.refine(isValidPromptMetricsTimeWindow, {