OpenBB-finance/OpenBB · error · ValueError

Invalid URL reference provided

Error message

Invalid URL reference provided

What it means

ValueError from the PdfResponseModel validator: a 'url' file reference was provided but contains no '://' substring, i.e. it is not a URL with a scheme. The check is intentionally simplistic — it only verifies that something like 'https://' appears in the string, catching local paths and bare hostnames.

Source

Thrown at openbb_platform/extensions/platform_api/openbb_platform_api/response_models.py:133

    )

    @model_validator(mode="after")
    @classmethod
    def validate_model(cls, values) -> "PdfResponseModel":
        """Validate the PDF content."""
        # pylint: disable=import-outside-toplevel
        import base64  # noqa
        from io import BytesIO

        content = getattr(values, "content", None)
        file_reference = getattr(values, "url", None)
        filename = getattr(values, "filename", "")

        if not content and not file_reference:
            raise ValueError("Either 'content' or 'url' must be provided.")

        if file_reference and "://" not in file_reference:
            raise ValueError("Invalid URL reference provided")

        if content:
            pdf = (
                base64.b64encode(BytesIO(content).getvalue()).decode("utf-8")
                if isinstance(content, bytes)
                else content
            )

        values.content = pdf
        if file_reference:
            values.url = file_reference
        elif hasattr(values, "url"):
            del values.url
        values.data_format = {"data_type": "pdf", "filename": filename}

        return values

View on GitHub (pinned to 3e071fcc2c)

Solutions

  1. Use a fully-qualified URL: url="https://cdn.example.com/report.pdf"
  2. If the PDF is local, load it and pass content=open(path, 'rb').read() instead of url
  3. When building URLs dynamically, use urllib.parse.urlunparse or f"https://{host}{path}" to keep the scheme explicit

Example fix

# before
PdfResponseModel(filename="report.pdf", url="/data/report.pdf")

# after
PdfResponseModel(filename="report.pdf", url="file:///data/report.pdf")
# or
PdfResponseModel(filename="report.pdf", content=open("/data/report.pdf", "rb").read())
Defensive patterns

Strategy: validation

Validate before calling

from urllib.parse import urlparse

if url and "://" not in url:
    parsed = urlparse(url)
    if not parsed.scheme:
        url = f"https://{url}"  # or reject explicitly
    if "://" not in url:
        raise ValueError(f"url lacks a scheme: {url}")

Type guard

def is_schemed_url(url: str | None) -> bool:
    return bool(url) and "://" in url

Try / catch

try:
    model = PdfResponseModel(filename=name, url=url)
except ValueError as e:
    if "Invalid URL reference" in str(e):
        model = PdfResponseModel(filename=name, url=f"https://{url}")
    else:
        raise

Prevention

When it happens

Trigger: PdfResponseModel(url="/data/report.pdf") or url="cdn.example.com/report.pdf" — both lack '://'. Only strings such as https://..., s3://..., file://... pass.

Common situations: Passing a local filesystem path or an SMB mount where a hosted URL was expected, config values holding just host+path without the scheme, URLs assembled by string concatenation that dropped the 'https://' prefix, relative URLs scraped from HTML (href="/files/x.pdf").

Related errors


AI-assisted analysis of OpenBB-finance/OpenBB@3e071fcc2c (2026-08-14). Data as JSON: /api/errors/f4e8d7c48f119a88. Report an issue: GitHub.