{"record":{"id":"7c7d5d18a64b46df","repo":"OpenBB-finance/OpenBB","slug":"invalid-json-format-for-filters-dict-e","errorCode":null,"errorMessage":"Invalid JSON format for 'filters_dict': {e}","messagePattern":"Invalid JSON format for 'filters_dict': (.+?)","errorType":"validation","errorClass":"OpenBBError","httpStatus":null,"severity":"error","filePath":"openbb_platform/providers/finviz/openbb_finviz/models/equity_screener.py","lineNumber":166,"sourceCode":"        \"\"\"Check to reject running template file.\"\"\"\n        if v is not None and v == \"screener_template\":\n            raise OpenBBError(\n                f\"Invalid preset '{v}'. Please rename the file to use as a preset.\"\n            )\n        return v if v else None\n\n    @field_validator(\"filters_dict\", mode=\"before\", check_fields=False)\n    @classmethod\n    def validate_filters_dict(cls, v):\n        \"\"\"Validate the filters_dict.\"\"\"\n        if isinstance(v, str):\n            # pylint: disable=import-outside-toplevel\n            import json\n\n            try:\n                v = json.loads(v)\n            except json.JSONDecodeError as e:\n                raise OpenBBError(f\"Invalid JSON format for 'filters_dict': {e}\") from e\n        if v is not None and not isinstance(v, dict):\n            raise OpenBBError(\n                \"Invalid 'filters_dict' format. Must be a dictionary or serialized JSON string.\"\n            )\n\n        return v\n\n\nclass FinvizEquityScreenerData(EquityScreenerData):\n    \"\"\"Finviz Equity Screener Data. Actual returned data varies by the 'metric' parameter.\"\"\"\n\n    __alias_dict__ = {\n        \"symbol\": \"Ticker\",\n        \"name\": \"Company\",\n        \"earnings_date\": \"Earnings\",\n        \"sector\": \"Sector\",\n        \"industry\": \"Industry\",\n        \"country\": \"Country\",","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/providers/finviz/openbb_finviz/models/equity_screener.py#L148-L184","documentation":"Raised when the `filters_dict` parameter is passed as a string but json.loads fails with JSONDecodeError. The query model accepts either a dict or a serialized JSON string; if a string, it must be parseable JSON. Common JSON syntax faults (trailing commas, single quotes, unquoted keys) trigger this.","triggerScenarios":"Passing filters_dict=\"{'Debt/Equity': 'Over 0.5'}\" (Python repr, single quotes); trailing commas; unquoted keys; a truncated string from shell escaping issues on the CLI.","commonSituations":"Building the JSON via f-strings or str(dict) instead of json.dumps; shell quoting on the CLI that eats inner double quotes; LLM- or template-generated filter strings.","solutions":["Pass a real dict instead of a string when using the Python API","If a string is required (CLI), produce it with json.dumps, not str()","Validate the string parses with json.loads before sending"],"exampleFix":"# before\nq = FinvizEquityScreenerQueryParams(filters_dict=\"{'Debt/Equity': 'Over 0.5'}\")  # single quotes\n\n# after\nimport json\nq = FinvizEquityScreenerQueryParams(filters_dict={\"Debt/Equity\": \"Over 0.5\"})\n# or on the CLI: --filters_dict '{\"Debt/Equity\": \"Over 0.5\"}'","handlingStrategy":"validation","validationCode":"import json\n\nif isinstance(filters_dict, str):\n    json.loads(filters_dict)  # raises early with a clear JSONDecodeError if malformed\n# better: pass a dict and let json.dumps handle serialization when needed","typeGuard":"def is_valid_filters_json(v) -> bool:\n    if isinstance(v, dict):\n        return True\n    if isinstance(v, str):\n        try:\n            return isinstance(json.loads(v), dict)\n        except json.JSONDecodeError:\n            return False\n    return False","tryCatchPattern":"import json\nfrom openbb_core.app.model.obb_error import OpenBBError\n\ntry:\n    q = FinvizEquityScreenerQueryParams(filters_dict=filters_dict)\nexcept OpenBBError as e:\n    if \"Invalid JSON\" in str(e):\n        filters_dict = json.dumps(dict_from_elsewhere)  # rebuild correctly\n        q = FinvizEquityScreenerQueryParams(filters_dict=filters_dict)\n    else:\n        raise","preventionTips":["Build JSON strings with json.dumps, never str() or f-strings","Pass dicts through the Python API; strings only where the CLI forces it","Lint user-supplied filter JSON at the input boundary"],"tags":["openbb","finviz","validation","json","filters"],"backgroundTag":null,"analyzedSha":"3e071fcc2cd9f891cac6040ae60296dba76dab46","analyzedAt":"2026-08-14T23:40:48.960Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}