{"record":{"id":"884e2f12119b6b93","repo":"langchain-ai/deepagents","slug":"invalid-json-in-model-params-json-str-r-expe","errorCode":null,"errorMessage":"Invalid JSON in --model-params: {json_str!r}. Expected format: --model-params '{\"key\": \"value\"}'","messagePattern":"Invalid JSON in --model-params: (.+?)\\. Expected format: --model-params '(.+?)'","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/code/deepagents_code/app.py","lineNumber":1986,"sourceCode":"            msg = \"Unbalanced braces in --model-params value\"\n            raise ValueError(msg)\n        json_str = after[: end + 1]\n        rest = after[end + 1 :].lstrip()\n    else:\n        # Non-brace, non-quoted — take the next whitespace-delimited token.\n        parts = after.split(None, 1)\n        json_str = parts[0]\n        rest = parts[1] if len(parts) > 1 else \"\"\n\n    remaining = f\"{before} {rest}\".strip()\n    try:\n        params = json.loads(json_str)\n    except json.JSONDecodeError:\n        msg = (\n            f\"Invalid JSON in --model-params: {json_str!r}. \"\n            'Expected format: --model-params \\'{\"key\": \"value\"}\\''\n        )\n        raise ValueError(msg) from None\n    if not isinstance(params, dict):\n        msg = \"--model-params must be a JSON object, got \" + type(params).__name__\n        raise TypeError(msg)\n    return remaining, params\n\n\ndef _format_model_params(extra_kwargs: dict[str, Any] | None) -> str:\n    \"\"\"Render `--model-params` as a stable, key-sorted JSON suffix.\n\n    Args:\n        extra_kwargs: The parsed `--model-params` payload, or `None`.\n\n    Returns:\n        ` with model params {json}` when `extra_kwargs` is non-empty;\n        otherwise an empty string so callers can unconditionally concatenate.\n    \"\"\"\n    if not extra_kwargs:\n        return \"\"","sourceCodeStart":1968,"sourceCodeEnd":2004,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/code/deepagents_code/app.py#L1968-L2004","documentation":"`_extract_model_params_flag` parses the `--model-params` CLI value with `json.loads`. If parsing fails (JSONDecodeError), it raises this ValueError showing the offending input and the expected quoting format, so the user knows the shell mangled or malformed their JSON rather than silently dropping the flag.","triggerScenarios":"Invoking the CLI with `--model-params <value>` where the value is not valid JSON: unbalanced braces, single-quoted JSON, keys/values missing quotes, or shell-stripped quotes (e.g. `--model-params {\"key\": \"value\"}` unquoted so the shell eats the braces).","commonSituations":"Developers pasting JSON examples into shells where outer quotes are consumed; Windows cmd quoting differences; using single quotes inside the JSON; forgetting that the whole argument must be one shell word.","solutions":["Wrap the whole JSON value in single quotes: --model-params '{\"temperature\": 0}'","Validate the JSON first with `python -c \"import json;json.loads('<value>')\"` before passing it","On Windows cmd/PowerShell, use escaped double quotes: --model-params \"{\\\"temperature\\\": 0}\"","If building the flag programmatically, use json.dumps on the dict instead of string interpolation"],"exampleFix":"// before\n--model-params {\"temperature\": 0}\n// after\n--model-params '{\"temperature\": 0}'","handlingStrategy":"validation","validationCode":"import json\nparams = json.loads(json_str)  # raises before the call if malformed\nassert isinstance(params, dict)\n# then pass json.dumps(params) as the --model-params value","typeGuard":"def is_json_object(s: str) -> bool:\n    try:\n        return isinstance(json.loads(s), dict)\n    except json.JSONDecodeError:\n        return False","tryCatchPattern":"try:\n    remaining, params = _extract_model_params_flag(argv)\nexcept ValueError as exc:\n    print(f\"usage: {exc}\")  # shows the expected format\n    sys.exit(2)","preventionTips":["Always single-quote the whole JSON value on the command line","Build the argument with json.dumps rather than string templates","Be aware of shell quoting differences on Windows vs POSIX","Validate JSON with python -c before invoking the CLI"],"tags":["cli","json-parsing","argument-validation"],"backgroundTag":"invalid-json-input","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}