{"record":{"id":"582c3c6b13af7321","repo":"mastra-ai/mastra","slug":"structured-output-returned-no-object","errorCode":null,"errorMessage":"Structured output returned no object","messagePattern":"Structured output returned no object","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/core/src/processors/processors/system-prompt-scrubber.ts","lineNumber":318,"sourceCode":"        this.strategy === 'redact'\n          ? baseSchema.extend({\n              redacted_content: z.string().describe('Redacted content').nullable(),\n            })\n          : baseSchema;\n\n      let result: SystemPromptDetectionResult;\n      if (isSupportedLanguageModel(model)) {\n        const response = await this.detectionAgent.generate(text, {\n          structuredOutput: {\n            ...(this.structuredOutputOptions ?? {}),\n            schema,\n          },\n          requestContext,\n          ...observabilityContext,\n        });\n\n        if (!response.object) {\n          throw new Error('Structured output returned no object');\n        }\n        result = response.object;\n      } else {\n        const standardSchema = toStandardSchema(schema as PublicSchema);\n        const response = await this.detectionAgent.generateLegacy(text, {\n          output: standardSchemaToJSONSchema(standardSchema),\n          requestContext,\n          ...observabilityContext,\n        });\n\n        result = response.object as SystemPromptDetectionResult;\n      }\n\n      return result;\n    } catch (error) {\n      console.warn('[SystemPromptScrubber] Detection agent failed:', error);\n      return {\n        detections: null,","sourceCodeStart":300,"sourceCodeEnd":336,"githubUrl":"https://github.com/mastra-ai/mastra/blob/75dd419e613fe9c39f846ffc500716141b74fda6/packages/core/src/processors/processors/system-prompt-scrubber.ts#L300-L336","documentation":"In `detectSystemPrompts`, the scrubber calls the model with a structured-output schema and expects `response.object` to contain the parsed detections. When the model returns no object (empty/abstained generation, refused output, or provider returning nothing parseable), it throws 'Structured output returned no object'. This is a runtime failure of the detection step, not a constructor-time config error.","triggerScenarios":"The detection agent's generate call resolves with `response.object === undefined` — e.g. the model produced no valid JSON matching the schema, the provider returned an empty completion, or finish reasons like content-filter/refusal left `object` unset.","commonSituations":"Weak/underspecified models failing to emit schema-conformant JSON, models refusing to analyze prompts, streaming parse hiccups, or input text that trips safety filters.","solutions":["Retry with a more capable model that reliably supports structured output (e.g. gpt-4o class models).","Check the raw response/finish reason and token usage to see whether the model refused or was truncated.","Shorten or sanitize the input text and retry; ensure no content-filter triggers.","Wrap the detect call in try/catch and fall back to `customPatterns`-only matching when LLM detection fails."],"exampleFix":"// before\nconst detections = await scrubber.detectSystemPrompts(text);\n// after\nlet detections;\ntry {\n  detections = await scrubber.detectSystemPrompts(text);\n} catch (e) {\n  if (e.message.includes('returned no object')) detections = scrubber.matchCustomPatterns(text);\n  else throw e;\n}","handlingStrategy":"fallback","validationCode":null,"typeGuard":"function hasObject<T>(r: { object?: T }): r is { object: T } {\n  return r.object !== undefined && r.object !== null;\n}","tryCatchPattern":"try {\n  result = await scrubber.detectSystemPrompts(text);\n} catch (e) {\n  if (e.message.includes('returned no object')) {\n    result = []; // fall back to custom-pattern-only behavior\n  } else throw e;\n}","preventionTips":["Use models with strong structured-output support for detection.","Keep input text within reasonable length and free of filter-triggering content.","Always provide customPatterns so a failed LLM detection still yields partial results.","Log finish reasons/tokens from the underlying generate call to diagnose recurring empty objects."],"tags":["llm","structured-output","runtime","detection"],"backgroundTag":"empty-structured-output","analyzedSha":"75dd419e613fe9c39f846ffc500716141b74fda6","analyzedAt":"2026-08-30T00:15:31.844Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}