mastra-ai/mastra · error
Structured output returned no object
Error message
Structured output returned no object
What it means
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.
Source
Thrown at packages/core/src/processors/processors/system-prompt-scrubber.ts:318
this.strategy === 'redact'
? baseSchema.extend({
redacted_content: z.string().describe('Redacted content').nullable(),
})
: baseSchema;
let result: SystemPromptDetectionResult;
if (isSupportedLanguageModel(model)) {
const response = await this.detectionAgent.generate(text, {
structuredOutput: {
...(this.structuredOutputOptions ?? {}),
schema,
},
requestContext,
...observabilityContext,
});
if (!response.object) {
throw new Error('Structured output returned no object');
}
result = response.object;
} else {
const standardSchema = toStandardSchema(schema as PublicSchema);
const response = await this.detectionAgent.generateLegacy(text, {
output: standardSchemaToJSONSchema(standardSchema),
requestContext,
...observabilityContext,
});
result = response.object as SystemPromptDetectionResult;
}
return result;
} catch (error) {
console.warn('[SystemPromptScrubber] Detection agent failed:', error);
return {
detections: null,View on GitHub (pinned to 75dd419e61)
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.
Example fix
// before
const detections = await scrubber.detectSystemPrompts(text);
// after
let detections;
try {
detections = await scrubber.detectSystemPrompts(text);
} catch (e) {
if (e.message.includes('returned no object')) detections = scrubber.matchCustomPatterns(text);
else throw e;
} Defensive patterns
Strategy: fallback
Type guard
function hasObject<T>(r: { object?: T }): r is { object: T } {
return r.object !== undefined && r.object !== null;
} Try / catch
try {
result = await scrubber.detectSystemPrompts(text);
} catch (e) {
if (e.message.includes('returned no object')) {
result = []; // fall back to custom-pattern-only behavior
} else throw e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: Weak/underspecified models failing to emit schema-conformant JSON, models refusing to analyze prompts, streaming parse hiccups, or input text that trips safety filters.
Related errors
- Analysis step failed to produce results
- Analysis step failed to produce results for reason generatio
- structuredOutput object is undefined
- CursorSDKAgent does not support structuredOutput because the
- Response body is null
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/582c3c6b13af7321.
Report an issue: GitHub.