opendataloader-project/opendataloader-pdf · error · RuntimeError

Conversion completed but no '{ext}' output file was generate

Error message

Conversion completed but no '{ext}' output file was generated.

What it means

RuntimeError raised when convert() returned, the expected {stem}{ext} output is absent, but OTHER files DO exist in the temp dir (none with the matching extension). This points to a filename mismatch: the Java CLI wrote output using a different stem or extension than the Python wrapper predicted from input_file.stem + ext_map. The wrapper then cannot locate the result even though conversion succeeded.

Source

Thrown at python/opendataloader-pdf-mcp/src/opendataloader_pdf_mcp/server.py:166

            kwargs["hybrid_fallback"] = True
        if image_dir is not None:
            kwargs["image_dir"] = image_dir

        opendataloader_pdf.convert(**kwargs)

        # Find and read the output file
        stem = input_file.stem
        output_file = Path(tmp_dir) / f"{stem}{ext}"

        if not output_file.is_file():
            files = [f for f in Path(tmp_dir).iterdir() if f.is_file()]
            if not files:
                raise RuntimeError(
                    "Conversion completed but no output file was generated."
                )
            matching_ext = sorted(f for f in files if f.suffix == ext)
            if not matching_ext:
                raise RuntimeError(
                    f"Conversion completed but no '{ext}' output file was generated."
                )
            output_file = matching_ext[0]

        return output_file.read_text(encoding="utf-8")


def main():
    """Run the MCP server."""
    mcp.run()


if __name__ == "__main__":
    main()

View on GitHub (pinned to a7789b8e77)

Solutions

  1. List the temp dir contents when debugging: the present files reveal the actual naming the CLI used (e.g. a sanitized stem or a different extension).
  2. Avoid filenames with characters the CLI may rewrite; use ASCII filenames without spaces for predictable output stems.
  3. Confirm the format maps to a single file, not a directory (e.g. image extraction can produce multiple files).
  4. After changing CLI output behaviour, ensure the MCP wrapper's stem/ext prediction stays in sync (run npm run sync).

Example fix

# before: stem mismatch — file is 'My Report.pdf' -> output stem 'My_Report'
convert(input_path="My Report.pdf", format="markdown")  # looks for 'My Report.md'
# after: ASCII filename without spaces
convert(input_path="my_report.pdf", format="markdown")  # finds 'my_report.md'
Defensive patterns

Strategy: validation

Validate before calling

# Pre-check: use ASCII filenames without spaces so the CLI's output stem matches input_file.stem.
import re
def safe_stem(path: str) -> bool:
    stem = Path(path).stem
    return bool(re.fullmatch(r"[A-Za-z0-9_.-]+", stem))

Type guard

def is_extension_mismatch_error(exc: RuntimeError) -> bool:
    return isinstance(exc, RuntimeError) and "output file was generated." in str(exc) and "'" in str(exc)

Try / catch

try:
    text = convert(input_path=path, format="markdown")
except RuntimeError as e:
    if "output file was generated." in str(e) and "'" in str(e):
        # other files exist but none match ext — list tmp_dir to find the real name
        log.warning("Output stem/ext mismatch; rename input to ASCII without spaces and retry")
    raise

Prevention

When it happens

Trigger: input_file.stem differs from the stem the Java CLI uses for the output filename — e.g. the CLI sanitizes/replaces characters, uses the PDF's internal /Title, or appends a suffix. Or the output extension differs from ext_map's mapping for the chosen format (e.g. tagged-pdf vs pdf, or a format that produces a directory not a single file).

Common situations: Source filename contains characters the CLI normalizes (spaces, unicode) so the output stem differs. The format produces a bundle/directory rather than a single file. A version change altered the CLI's output naming convention while the MCP wrapper's prediction stayed fixed.

Related errors


AI-assisted analysis of opendataloader-project/opendataloader-pdf@a7789b8e77 (2026-08-14). Data as JSON: /api/errors/bebbc6110c25a40d. Report an issue: GitHub.