{"record":{"id":"9bbe5f8bb7967824","repo":"OpenBB-finance/OpenBB","slug":"invalid-parse-as-value-must-be-one-of-table-c","errorCode":null,"errorMessage":"Invalid parse_as value. Must be one of 'table', 'chart', or 'text'.","messagePattern":"Invalid parse_as value\\. Must be one of 'table', 'chart', or 'text'\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"openbb_platform/extensions/platform_api/openbb_platform_api/response_models.py","lineNumber":219,"sourceCode":"\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\n\n        if content.__class__.__name__ == \"Figure\":\n            values.parse_as = \"chart\"\n            try:\n                content = content.to_json()","sourceCodeStart":201,"sourceCodeEnd":237,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/extensions/platform_api/openbb_platform_api/response_models.py#L201-L237","documentation":"ValueError from the OmniWidgetResponseModel validator: the optional 'parse_as' field was supplied but is not one of the three supported values 'table', 'chart', or 'text'. The check is exact-match against a tuple, so 'Table', 'TABLE ', 'json', or 'dataframe' all fail.","triggerScenarios":"OmniWidgetResponseModel(content=df, parse_as=\" dataframe\") or parse_as=\"json\". Any value outside ('table', 'chart', 'text') — including case/whitespace variants, since there is no normalization — raises.","commonSituations":"Frontends sending uppercase or plural forms ('tables', 'charts'), configs copied from another tool whose format names differ, enum drift if the accepted set changes across versions, trailing whitespace from template-filled config values.","solutions":["Use exactly one of: parse_as=\"table\", parse_as=\"chart\", or parse_as=\"text\"","Omit parse_as entirely when you want the model to auto-detect the data format from the content","Normalize external input before constructing: value.strip().lower(), then check membership in {\"table\", \"chart\", \"text\"}"],"exampleFix":"# before\nOmniWidgetResponseModel(content=data, parse_as=\"Table\")\n\n# after\nOmniWidgetResponseModel(content=data, parse_as=\"table\")","handlingStrategy":"validation","validationCode":"VALID = {\"table\", \"chart\", \"text\"}\nif parse_as is not None:\n    parse_as = parse_as.strip().lower()\n    if parse_as not in VALID:\n        raise ValueError(f\"parse_as must be one of {sorted(VALID)}, got {parse_as!r}\")\nmodel = OmniWidgetResponseModel(content=content, parse_as=parse_as)","typeGuard":"def is_valid_parse_as(value: object) -> bool:\n    return value is None or (\n        isinstance(value, str) and value.strip().lower() in {\"table\", \"chart\", \"text\"}\n    )","tryCatchPattern":"try:\n    model = OmniWidgetResponseModel(content=data, parse_as=parse_as)\nexcept ValueError as e:\n    if \"Invalid parse_as value\" in str(e):\n        model = OmniWidgetResponseModel(content=data)  # let the model auto-detect\n    else:\n        raise","preventionTips":["Normalize external parse_as values with .strip().lower() before use","Omit parse_as to let the model infer the format from the content","Pin accepted values in your API contract (enum) so clients cannot send variants"],"tags":["pydantic","validation","widgets","enum","response-model"],"backgroundTag":null,"analyzedSha":"3e071fcc2cd9f891cac6040ae60296dba76dab46","analyzedAt":"2026-08-14T23:40:48.960Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}