{"record":{"id":"c109b8db7b1c2d62","repo":"mastra-ai/mastra","slug":"could-not-derive-prompt-block-id-from-name-please","errorCode":null,"errorMessage":"Could not derive prompt block ID from name. Please provide an explicit id.","messagePattern":"Could not derive prompt block ID from name\\. Please provide an explicit id\\.","errorType":"http","errorClass":"HTTPException","httpStatus":400,"severity":"error","filePath":"packages/server/src/server/handlers/stored-prompt-blocks.ts","lineNumber":179,"sourceCode":"    requestContext,\n  }) => {\n    try {\n      const storage = mastra.getStorage();\n\n      if (!storage) {\n        throw new HTTPException(500, { message: 'Storage is not configured' });\n      }\n\n      const promptBlockStore = await storage.getStore('promptBlocks');\n      if (!promptBlockStore) {\n        throw new HTTPException(500, { message: 'Prompt blocks storage domain is not available' });\n      }\n\n      // Derive ID from name if not explicitly provided\n      const id = providedId || toSlug(name);\n\n      if (!id) {\n        throw new HTTPException(400, {\n          message: 'Could not derive prompt block ID from name. Please provide an explicit id.',\n        });\n      }\n\n      // Check if prompt block with this ID already exists\n      const existing = await promptBlockStore.getById(id);\n      if (existing) {\n        throw new HTTPException(409, { message: `Prompt block with id ${id} already exists` });\n      }\n\n      await promptBlockStore.create({\n        promptBlock: {\n          id,\n          authorId,\n          metadata: scopeStoredResourceMetadata(metadata, await getStoredResourceScope(mastra, requestContext)),\n          name,\n          description,\n          content,","sourceCodeStart":161,"sourceCodeEnd":197,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/server/src/server/handlers/stored-prompt-blocks.ts#L161-L197","documentation":"When creating a stored prompt block without an explicit `id`, the server derives one by slugifying the provided `name` via `toSlug(name)`. If the result is an empty string (e.g. the name contained only characters stripped by slugification), creation is aborted with this 400 error asking for an explicit id. The slug must be non-empty to be a usable record key.","triggerScenarios":"POST /stored/prompt-blocks with a body that omits `id` and has a `name` consisting solely of characters removed by toSlug (e.g. '!!!', '   ', '///', or an emoji-only name).","commonSituations":"Programmatic generation of prompt blocks where names are templated or user-supplied and may collapse to empty after slugification; names containing only non-ASCII/special characters.","solutions":["Pass an explicit `id` field in the create request body","Provide a `name` that slugifies to a non-empty value (include letters or numbers)","Sanitize names client-side before submitting and fall back to an explicit id"],"exampleFix":"// before\nawait client.createStoredPromptBlock({ name: '!!!' })\n// after\nawait client.createStoredPromptBlock({ id: 'my-block-1', name: '!!!' })","handlingStrategy":"validation","validationCode":"function slugify(name: string): string {\n  return name.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/(^-|-$)/g, '');\n}\nif (!id && !slugify(name)) {\n  throw new Error(`Name \"${name}\" slugifies to an empty id; provide an explicit id`);\n}","typeGuard":"function canDeriveId(body: { id?: string; name: string }): boolean {\n  return Boolean(body.id || body.name.replace(/[^a-zA-Z0-9]/g, ''));\n}","tryCatchPattern":null,"preventionTips":["Always send an explicit id for programmatically generated blocks","Validate that names contain at least one letter or digit before submitting","Keep a unit test that slugifies every user-facing name template"],"tags":["validation","server","slug"],"backgroundTag":"invalid-resource-id","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}