pola-rs/polars · error · ValueError
invalid Config string (did you mean to use…
Error message
invalid Config string (did you mean to use `load_from_file`?)
What it means
Raised by Config.load when the given string is not valid JSON. Since load expects the JSON string produced by Config.save(), a JSONDecodeError usually means the user passed a file path instead of file contents.
Solutions
- Use Config.load_from_file(path) when you have a file path
- Pass the exact JSON string returned by Config.save()
- Validate the string parses as JSON before calling load
Example fix
// before
pl.Config.load('~/.polars_cfg.json') # ValueError
// after
pl.Config.load_from_file('~/.polars_cfg.json') Defensive patterns
Strategy: try-catch
Validate before calling
import json
try:
json.loads(cfg)
except json.JSONDecodeError:
raise ValueError('config string is not JSON; use load_from_file for paths') Type guard
def is_json(s: str) -> bool:
try:
json.loads(s)
return True
except json.JSONDecodeError:
return False Try / catch
try:
pl.Config.load(cfg)
except ValueError:
# maybe a path was passed
pl.Config.load_from_file(cfg) Prevention
- Remember load() takes a JSON string, load_from_file() a path
- Only pass output of Config.save() to load
- Sanity-check with json.loads first
When it happens
Trigger: Calling Config.load('/path/to/config.json') (a path, not a JSON string) or passing any non-JSON string.
Common situations: Confusing Config.load (string) with Config.load_from_file (path); passing a dict/serialized YAML instead of the polars JSON format.
Understand the failure class
Background: JSON parse error: "Unexpected token" / "not valid JSON" / "failed to parse" — what JSON parsers are really complaining about — this error's family across 45 libraries.
Related errors
- `Config` has no option
- {credential_provider}
- Deserialization from JSON not implemented for
- expected list or dict of objects
- `Expr.str.json_decode` needs an explicitly given `dtype`…
AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18).
Data as JSON: /api/errors/c95b9425b4f451df.
Report an issue: GitHub.
Appendix: source
Thrown at py-polars/src/polars/config.py:408
def load(cls, cfg: str) -> Config:
"""
Load (and set) previously saved Config options from a JSON string.
Parameters
----------
cfg : str
JSON string produced by `Config.save()`.
See Also
--------
load_from_file : Load (and set) Config options from a JSON file.
save : Save the current set of Config options as a JSON string or file.
"""
try:
options = json.loads(cfg)
except json.JSONDecodeError as err:
msg = "invalid Config string (did you mean to use `load_from_file`?)"
raise ValueError(msg) from err
cfg_load = Config()
opts = options.get("environment", {})
if "POLARS_ENGINE_AFFINITY" in opts:
# A saved affinity value replaces any object affinity.
set_engine_affinity_override(None)
for key, opt in opts.items():
if opt is None:
os.environ.pop(key, None)
else:
os.environ[key] = opt
for cfg_methodname, value in options.get("direct", {}).items():
if hasattr(cfg_load, cfg_methodname):
getattr(cfg_load, cfg_methodname)(value)
plr.config_reload_env_vars()
return cfg_loadView on GitHub (pinned to fe841f959e)