{"record":{"id":"50dda7aa9efdfc27","repo":"OpenBB-finance/OpenBB","slug":"content-cannot-be-empty","errorCode":null,"errorMessage":"Content cannot be empty.","messagePattern":"Content cannot be empty\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"openbb_platform/extensions/platform_api/openbb_platform_api/response_models.py","lineNumber":214,"sourceCode":"    data_format: dict | None = Field(\n        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) -> \"OmniWidgetResponseModel\":\n        \"\"\"Validate the Omni widget content.\"\"\"\n        # pylint: disable=import-outside-toplevel\n        import json  # noqa\n        import re\n        import pandas as pd\n\n        content = getattr(values, \"content\", None)\n\n        if content is None:\n            raise ValueError(\"Content cannot be empty.\")\n\n        parse_as = getattr(values, \"parse_as\", None)\n\n        if parse_as and parse_as not in (\"table\", \"chart\", \"text\"):\n            raise ValueError(\n                \"Invalid parse_as value. Must be one of 'table', 'chart', or 'text'.\"\n            )\n\n        # If parameter was supplied, assume the data is formatted correctly.\n        if content and parse_as:\n            data_format = {\n                \"data_type\": \"object\",\n                \"parse_as\": parse_as,\n            }\n            values.data_format = data_format\n            del values.parse_as\n\n            return values","sourceCodeStart":196,"sourceCodeEnd":232,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/extensions/platform_api/openbb_platform_api/response_models.py#L196-L232","documentation":"ValueError from the OmniWidgetResponseModel validator: the 'content' field is None. Note this is a strict None check, not a truthiness check — an empty string or empty dict passes this guard (and may fail later parsing instead), while a missing/None content fails here.","triggerScenarios":"Constructing OmniWidgetResponseModel(content=None) or omitting content entirely when building the model from a dict that lacks the key (getattr default is None). Upstream data fetchers returning None on failure and that value flowing straight into the model.","commonSituations":"API endpoints whose data source returned nothing and the handler still builds the response model, dict keys named differently ('data' vs 'content'), refactors that renamed the field while callers still send the old key, JSON deserialization where content was explicitly null.","solutions":["Supply actual content: a DataFrame, dict, list, or string with the widget data","Guard upstream: skip model construction or return an empty-widget placeholder when the fetch yields None","Check for key-name mismatches between the producer dict and the model field ('data'/'payload' vs 'content')"],"exampleFix":"# before\nOmniWidgetResponseModel(chart=True, content=df if fetched else None)\n\n# after\nif df is None:\n    df = pd.DataFrame()\nOmniWidgetResponseModel(chart=True, content=df)","handlingStrategy":"validation","validationCode":"if content is None:\n    raise ValueError(\"upstream fetch returned no content; refusing to build widget\")\n# or substitute an explicit empty payload:\ncontent = content if content is not None else pd.DataFrame()\nmodel = OmniWidgetResponseModel(content=content, chart=chart)","typeGuard":"def content_is_present(content: object) -> bool:\n    return content is not None","tryCatchPattern":"try:\n    model = OmniWidgetResponseModel(content=content, chart=True)\nexcept ValueError as e:\n    if \"Content cannot be empty\" in str(e):\n        model = OmniWidgetResponseModel(content=pd.DataFrame(), chart=True)\n    else:\n        raise","preventionTips":["Guard upstream fetchers: None means skip or substitute, never pass through","Verify the producer dict uses the key 'content' (not 'data'/'payload')","Remember only None fails here — empty strings/objects pass but may break later parsing"],"tags":["pydantic","validation","widgets","response-model"],"backgroundTag":null,"analyzedSha":"3e071fcc2cd9f891cac6040ae60296dba76dab46","analyzedAt":"2026-08-14T23:40:48.960Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}