langchain-ai/deepagents · error · TypeError
--model-params must be a JSON object, got {type}
Error message
--model-params must be a JSON object, got {type} What it means
After successful JSON parsing, `_extract_model_params_flag` checks the result is a dict. JSON allows top-level arrays, strings, numbers, booleans, and null; `--model-params` only accepts an object of model kwargs, so anything else raises this TypeError naming the actual parsed type.
Source
Thrown at libs/code/deepagents_code/app.py:1989
rest = after[end + 1 :].lstrip()
else:
# Non-brace, non-quoted — take the next whitespace-delimited token.
parts = after.split(None, 1)
json_str = parts[0]
rest = parts[1] if len(parts) > 1 else ""
remaining = f"{before} {rest}".strip()
try:
params = json.loads(json_str)
except json.JSONDecodeError:
msg = (
f"Invalid JSON in --model-params: {json_str!r}. "
'Expected format: --model-params \'{"key": "value"}\''
)
raise ValueError(msg) from None
if not isinstance(params, dict):
msg = "--model-params must be a JSON object, got " + type(params).__name__
raise TypeError(msg)
return remaining, params
def _format_model_params(extra_kwargs: dict[str, Any] | None) -> str:
"""Render `--model-params` as a stable, key-sorted JSON suffix.
Args:
extra_kwargs: The parsed `--model-params` payload, or `None`.
Returns:
` with model params {json}` when `extra_kwargs` is non-empty;
otherwise an empty string so callers can unconditionally concatenate.
"""
if not extra_kwargs:
return ""
return f" with model params {json.dumps(extra_kwargs, sort_keys=True)}"
View on GitHub (pinned to a1af029e6e)
Solutions
- Wrap the value in a JSON object with the kwarg as key: --model-params '{"temperature": 0.5}'
- Check the value parses to an object: python -c "import json;d=json.loads('<v>');assert isinstance(d,dict)"
- For list-shaped settings, nest them under a key inside the object
Example fix
// before
--model-params '["temperature", 0.5]'
// after
--model-params '{"temperature": 0.5}' Defensive patterns
Strategy: type-guard
Validate before calling
parsed = json.loads(value)
if not isinstance(parsed, dict):
raise TypeError(f"--model-params needs a JSON object, got {type(parsed).__name__}") Type guard
def is_model_params_object(value: str) -> bool:
try:
return isinstance(json.loads(value), dict)
except json.JSONDecodeError:
return False Try / catch
try:
remaining, params = _extract_model_params_flag(argv)
except TypeError as exc:
print(exc) # names the parsed type
sys.exit(2) Prevention
- Top-level value must be {"key": value}; scalars/lists are rejected
- Nest list settings under a key instead of passing a bare JSON array
- Lint config generators to emit JSON objects only
When it happens
Trigger: Passing a valid-JSON-but-not-object value: `--model-params '[1,2]'`, `--model-params '"hello"'`, `--model-params '42'`, `--model-params 'null'`, or `--model-params 'true'`.
Common situations: Users intending a list of parameters, or passing a scalar value (a temperature number alone) expecting it to be treated as a setting.
Related errors
- Invalid JSON in --model-params: {json_str!r}. Expected forma
- --max-content must be positive
- --list must be positive
- -32002
- dcode: {message}
AI-assisted analysis of langchain-ai/deepagents@a1af029e6e (2026-08-29).
Data as JSON: /api/errors/c8e6d8802570a922.
Report an issue: GitHub.