OpenBB-finance/OpenBB · error · ValueError
Either 'content' or 'url' must be provided.
Error message
Either 'content' or 'url' must be provided.
What it means
ValueError from the PdfResponseModel validator: a PDF response must carry either raw/base64 'content' or a 'url' file reference; supplying neither leaves the model with nothing to serve and validation fails. Note both fields being empty is the failure — one of them is mandatory.
Source
Thrown at openbb_platform/extensions/platform_api/openbb_platform_api/response_models.py:130
default=None,
description="Leave this field empty. This is populated by the model_validator.",
json_schema_extra={"x-widget_config": {"exclude": True}},
)
@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}
View on GitHub (pinned to 3e071fcc2c)
Solutions
- Provide content (bytes are base64-encoded automatically, or pass a base64 str) or a url containing a scheme
- Fix the upstream fetch so content is populated before constructing the model
- If using a file reference, ensure it is a full URL like https://... (see also error 137 for the URL format check)
Example fix
# before PdfResponseModel(filename="report.pdf") # after PdfResponseModel(filename="report.pdf", content=pdf_bytes) # or PdfResponseModel(filename="report.pdf", url="https://cdn.example.com/report.pdf")
Defensive patterns
Strategy: validation
Validate before calling
if not content and not url:
raise ValueError("PDF response needs 'content' or 'url'")
if content:
kwargs["content"] = content
else:
kwargs["url"] = url
model = PdfResponseModel(filename=filename, **kwargs) Type guard
def has_pdf_payload(content, url) -> bool:
return bool(content) or bool(url) Try / catch
try:
model = PdfResponseModel(filename=name, content=content, url=url)
except ValueError as e:
if "Either 'content' or 'url'" in str(e):
model = PdfResponseModel(
filename=name, url="https://fallback.example.com/report.pdf"
)
else:
raise Prevention
- Assert truthiness of content or url before building the model
- Treat empty bytes (b"") as absent — the validator does
- Name the fields exactly 'content' and 'url'
When it happens
Trigger: Constructing PdfResponseModel(filename="report.pdf") with no content and no url; or a data pipeline where both keys were dropped/empty (content=None, url="") — falsy values count as absent because the check is truthiness-based.
Common situations: Building response models from dicts where the PDF bytes failed to download upstream and the code still constructs the model, passing an empty bytes literal b"", forgetting the field is named 'url' and using 'link' or 'path' instead.
Related errors
- Invalid URL reference provided
- Content cannot be empty.
- Invalid parse_as value. Must be one of 'table', 'chart', or
- At least one extension type must be selected.
- Incorrect email or password
AI-assisted analysis of OpenBB-finance/OpenBB@3e071fcc2c (2026-08-14).
Data as JSON: /api/errors/d986de6ce2b0d99e.
Report an issue: GitHub.