abi/screenshot-to-code · error · EmptyOutputError

Generation finished without producing any output.

Error message

Generation finished without producing any output.

What it means

EmptyOutputError is raised in Agent.run when _run_with_session returns a falsy result (empty/None assistant text) after the whole run completes 'successfully'. It exists so a run that yields no code does not get recorded as a valid completion; the recorder marks the run 'failed' with this error.

Source

Thrown at backend/agent/engine.py:357

            should_generate_images=self.should_generate_images,
            openai_api_key=self.openai_api_key,
            openai_base_url=self.openai_base_url,
            anthropic_api_key=self.anthropic_api_key,
            gemini_api_key=self.gemini_api_key,
            replicate_api_key=self.replicate_api_key,
            # Only advertise extraction when the request actually contains a
            # still image the runtime can crop. In particular, Gemini videos
            # share the image_url message shape but are not valid extractor
            # inputs.
            should_extract_assets=(
                self.should_extract_assets and bool(self.tool_runtime.input_images)
            ),
            recorder=self.recorder,
        )
        try:
            result = await self._run_with_session(session)
            if not result:
                raise EmptyOutputError()
            if self.recorder is not None:
                await self.recorder.record_run_end("completed", final_html=result)
            return result
        # BaseException so cancellation (client disconnect) still finalizes
        # the run record instead of leaving it stuck at "running".
        except BaseException as exc:
            if self.recorder is not None:
                await self.recorder.record_run_end(
                    "failed",
                    error="".join(
                        traceback.format_exception_only(type(exc), exc)
                    ).strip(),
                )
            raise
        finally:
            await session.close()

    async def _finalize_response(self, assistant_text: str) -> str:

View on GitHub (pinned to d026163f58)

Solutions

  1. Retry the generation: transient empty completions are the most common cause.
  2. Switch models — some models are more prone to ending without a final text turn.
  3. Inspect the recorded run log to see whether the final turn had tool calls only.
  4. If it recurs on one prompt, rephrase so the model must answer with code in its final message.
Defensive patterns

Strategy: retry

Try / catch

for attempt in range(2):
    try:
        return await engine.run(model, messages)
    except EmptyOutputError:
        if attempt == 1:
            raise

Prevention

When it happens

Trigger: The provider session finalizes but the accumulated final HTML/text is empty: the model returned only whitespace, all content arrived through paths that never populated the result, or the final turn's text was empty after tool stripping.

Common situations: Model responds purely with tool calls and no closing text, upstream API returned empty content in the final message, or streaming was cancelled near the end leaving result unpopulated.

Related errors


AI-assisted analysis of abi/screenshot-to-code@d026163f58 (2026-08-14). Data as JSON: /api/errors/fcb34989dc93c03c. Report an issue: GitHub.