{"record":{"id":"f4e8d7c48f119a88","repo":"OpenBB-finance/OpenBB","slug":"invalid-url-reference-provided","errorCode":null,"errorMessage":"Invalid URL reference provided","messagePattern":"Invalid URL reference provided","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"openbb_platform/extensions/platform_api/openbb_platform_api/response_models.py","lineNumber":133,"sourceCode":"    )\n\n    @model_validator(mode=\"after\")\n    @classmethod\n    def validate_model(cls, values) -> \"PdfResponseModel\":\n        \"\"\"Validate the PDF content.\"\"\"\n        # pylint: disable=import-outside-toplevel\n        import base64  # noqa\n        from io import BytesIO\n\n        content = getattr(values, \"content\", None)\n        file_reference = getattr(values, \"url\", None)\n        filename = getattr(values, \"filename\", \"\")\n\n        if not content and not file_reference:\n            raise ValueError(\"Either 'content' or 'url' must be provided.\")\n\n        if file_reference and \"://\" not in file_reference:\n            raise ValueError(\"Invalid URL reference provided\")\n\n        if content:\n            pdf = (\n                base64.b64encode(BytesIO(content).getvalue()).decode(\"utf-8\")\n                if isinstance(content, bytes)\n                else content\n            )\n\n        values.content = pdf\n        if file_reference:\n            values.url = file_reference\n        elif hasattr(values, \"url\"):\n            del values.url\n        values.data_format = {\"data_type\": \"pdf\", \"filename\": filename}\n\n        return values\n\n","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/extensions/platform_api/openbb_platform_api/response_models.py#L115-L151","documentation":"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.","triggerScenarios":"PdfResponseModel(url=\"/data/report.pdf\") or url=\"cdn.example.com/report.pdf\" — both lack '://'. Only strings such as https://..., s3://..., file://... pass.","commonSituations":"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\").","solutions":["Use a fully-qualified URL: url=\"https://cdn.example.com/report.pdf\"","If the PDF is local, load it and pass content=open(path, 'rb').read() instead of url","When building URLs dynamically, use urllib.parse.urlunparse or f\"https://{host}{path}\" to keep the scheme explicit"],"exampleFix":"# before\nPdfResponseModel(filename=\"report.pdf\", url=\"/data/report.pdf\")\n\n# after\nPdfResponseModel(filename=\"report.pdf\", url=\"file:///data/report.pdf\")\n# or\nPdfResponseModel(filename=\"report.pdf\", content=open(\"/data/report.pdf\", \"rb\").read())","handlingStrategy":"validation","validationCode":"from urllib.parse import urlparse\n\nif url and \"://\" not in url:\n    parsed = urlparse(url)\n    if not parsed.scheme:\n        url = f\"https://{url}\"  # or reject explicitly\n    if \"://\" not in url:\n        raise ValueError(f\"url lacks a scheme: {url}\")","typeGuard":"def is_schemed_url(url: str | None) -> bool:\n    return bool(url) and \"://\" in url","tryCatchPattern":"try:\n    model = PdfResponseModel(filename=name, url=url)\nexcept ValueError as e:\n    if \"Invalid URL reference\" in str(e):\n        model = PdfResponseModel(filename=name, url=f\"https://{url}\")\n    else:\n        raise","preventionTips":["Always construct URLs with an explicit scheme (https://, s3://, file://)","Use urlparse to validate/configure scheme handling before passing values","For local files pass content bytes instead of a path-style url"],"tags":["pydantic","validation","url","pdf","response-model"],"backgroundTag":null,"analyzedSha":"3e071fcc2cd9f891cac6040ae60296dba76dab46","analyzedAt":"2026-08-14T23:40:48.960Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}