{"record":{"id":"c04efbb5009185a6","repo":"langchain-ai/deepagents","slug":"model-params-requires-a-json-object-value","errorCode":null,"errorMessage":"--model-params requires a JSON object value","messagePattern":"--model-params requires a JSON object value","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/code/deepagents_code/app.py","lineNumber":1934,"sourceCode":"        Tuple of `(remaining_args, parsed_dict | None)`. Returns `None` for the\n            dict when the flag is absent.\n\n    Raises:\n        ValueError: If the value is missing, has unclosed quotes,\n            unbalanced braces, or is not valid JSON.\n        TypeError: If the parsed JSON is not a dict.\n    \"\"\"\n    flag = \"--model-params\"\n    idx = raw_arg.find(flag)\n    if idx == -1:\n        return raw_arg, None\n\n    before = raw_arg[:idx].rstrip()\n    after = raw_arg[idx + len(flag) :].lstrip()\n\n    if not after:\n        msg = \"--model-params requires a JSON object value\"\n        raise ValueError(msg)\n\n    # Determine the JSON string boundaries.\n    if after[0] in {\"'\", '\"'}:\n        quote = after[0]\n        end = -1\n        backslash_count = 0\n        for i, ch in enumerate(after[1:], start=1):\n            if ch == \"\\\\\":\n                backslash_count += 1\n                continue\n            if ch == quote and backslash_count % 2 == 0:\n                end = i\n                break\n            backslash_count = 0\n        if end == -1:\n            msg = f\"Unclosed {quote} in --model-params value\"\n            raise ValueError(msg)\n        # Parse the quoted token with shlex so escaped quotes are unescaped.","sourceCodeStart":1916,"sourceCodeEnd":1952,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/code/deepagents_code/app.py#L1916-L1952","documentation":"_extract_model_params_flag parses the value following the --model-params CLI flag. When there is nothing after the flag (only whitespace or end of input), it cannot build a JSON object and raises ValueError. The flag requires a JSON object payload such as {\"temperature\":0.2}.","triggerScenarios":"Invoking the CLI with --model-params as the last token, e.g. `dcode --model-params`, or with the flag followed only by whitespace.","commonSituations":"Copy-pasting a command where the JSON value ended up on a second line that the shell dropped; a script template where the JSON variable was empty; forgetting the value while exploring flags interactively.","solutions":["Append a JSON object after the flag: --model-params '{\"temperature\":0.2}'.","Quote the JSON if your shell strips braces, and verify the variable feeding the flag is non-empty.","If the value comes from a script, echo it first to confirm it expands to a JSON object."],"exampleFix":"# before\ndcode --model-params\n\n# after\ndcode --model-params '{\"temperature\": 0.2}'","handlingStrategy":"try-catch","validationCode":"parts = shlex.split(cmd)\nif \"--model-params\" in parts and parts.index(\"--model-params\") == len(parts) - 1:\n    raise SystemExit(\"--model-params needs a JSON object value\")","typeGuard":null,"tryCatchPattern":"try:\n    handle_command(argv)\nexcept ValueError as e:\n    if \"--model-params\" in str(e):\n        print(f\"usage: --model-params '<json object>' — {e}\")\n        sys.exit(2)\n    raise","preventionTips":["Always pass the JSON object in single quotes on the same line as the flag.","Validate the payload with json.loads before invoking the CLI.","Never template --model-params with a possibly-empty variable."],"tags":["cli","argument-parsing","json","python"],"backgroundTag":"invalid-cli-argument","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}