{"record":{"id":"d986de6ce2b0d99e","repo":"OpenBB-finance/OpenBB","slug":"either-content-or-url-must-be-provided","errorCode":null,"errorMessage":"Either 'content' or 'url' must be provided.","messagePattern":"Either 'content' or 'url' must be provided\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"openbb_platform/extensions/platform_api/openbb_platform_api/response_models.py","lineNumber":130,"sourceCode":"        default=None,\n        description=\"Leave this field empty. This is populated by the model_validator.\",\n        json_schema_extra={\"x-widget_config\": {\"exclude\": True}},\n    )\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","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/extensions/platform_api/openbb_platform_api/response_models.py#L112-L148","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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)"],"exampleFix":"# before\nPdfResponseModel(filename=\"report.pdf\")\n\n# after\nPdfResponseModel(filename=\"report.pdf\", content=pdf_bytes)\n# or\nPdfResponseModel(filename=\"report.pdf\", url=\"https://cdn.example.com/report.pdf\")","handlingStrategy":"validation","validationCode":"if not content and not url:\n    raise ValueError(\"PDF response needs 'content' or 'url'\")\nif content:\n    kwargs[\"content\"] = content\nelse:\n    kwargs[\"url\"] = url\nmodel = PdfResponseModel(filename=filename, **kwargs)","typeGuard":"def has_pdf_payload(content, url) -> bool:\n    return bool(content) or bool(url)","tryCatchPattern":"try:\n    model = PdfResponseModel(filename=name, content=content, url=url)\nexcept ValueError as e:\n    if \"Either 'content' or 'url'\" in str(e):\n        model = PdfResponseModel(\n            filename=name, url=\"https://fallback.example.com/report.pdf\"\n        )\n    else:\n        raise","preventionTips":["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'"],"tags":["pydantic","validation","pdf","response-model"],"backgroundTag":null,"analyzedSha":"3e071fcc2cd9f891cac6040ae60296dba76dab46","analyzedAt":"2026-08-14T23:40:48.960Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}