OpenBB-finance/OpenBB · error · OpenBBError
Invalid JSON format for 'filters_dict': {e}
Error message
Invalid JSON format for 'filters_dict': {e} What it means
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.
Source
Thrown at openbb_platform/providers/finviz/openbb_finviz/models/equity_screener.py:166
"""Check to reject running template file."""
if v is not None and v == "screener_template":
raise OpenBBError(
f"Invalid preset '{v}'. Please rename the file to use as a preset."
)
return v if v else None
@field_validator("filters_dict", mode="before", check_fields=False)
@classmethod
def validate_filters_dict(cls, v):
"""Validate the filters_dict."""
if isinstance(v, str):
# pylint: disable=import-outside-toplevel
import json
try:
v = json.loads(v)
except json.JSONDecodeError as e:
raise OpenBBError(f"Invalid JSON format for 'filters_dict': {e}") from e
if v is not None and not isinstance(v, dict):
raise OpenBBError(
"Invalid 'filters_dict' format. Must be a dictionary or serialized JSON string."
)
return v
class FinvizEquityScreenerData(EquityScreenerData):
"""Finviz Equity Screener Data. Actual returned data varies by the 'metric' parameter."""
__alias_dict__ = {
"symbol": "Ticker",
"name": "Company",
"earnings_date": "Earnings",
"sector": "Sector",
"industry": "Industry",
"country": "Country",View on GitHub (pinned to 3e071fcc2c)
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
Example fix
# before
q = FinvizEquityScreenerQueryParams(filters_dict="{'Debt/Equity': 'Over 0.5'}") # single quotes
# after
import json
q = FinvizEquityScreenerQueryParams(filters_dict={"Debt/Equity": "Over 0.5"})
# or on the CLI: --filters_dict '{"Debt/Equity": "Over 0.5"}' Defensive patterns
Strategy: validation
Validate before calling
import json
if isinstance(filters_dict, str):
json.loads(filters_dict) # raises early with a clear JSONDecodeError if malformed
# better: pass a dict and let json.dumps handle serialization when needed Type guard
def is_valid_filters_json(v) -> bool:
if isinstance(v, dict):
return True
if isinstance(v, str):
try:
return isinstance(json.loads(v), dict)
except json.JSONDecodeError:
return False
return False Try / catch
import json
from openbb_core.app.model.obb_error import OpenBBError
try:
q = FinvizEquityScreenerQueryParams(filters_dict=filters_dict)
except OpenBBError as e:
if "Invalid JSON" in str(e):
filters_dict = json.dumps(dict_from_elsewhere) # rebuild correctly
q = FinvizEquityScreenerQueryParams(filters_dict=filters_dict)
else:
raise Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Invalid 'filters_dict' format. Must be a dictionary or seria
- Invalid signal '{v}'. Available signals are: {SIGNALS_DESC_S
- Invalid industry '{v}'. Available industries are: {', '.join
- Invalid preset '{v}'. Please rename the file to use as a pre
- The screener variable {section}.{key} shouldn't exist!
AI-assisted analysis of OpenBB-finance/OpenBB@3e071fcc2c (2026-08-14).
Data as JSON: /api/errors/7c7d5d18a64b46df.
Report an issue: GitHub.