{"record":{"id":"6ecce68f464fc9d4","repo":"langchain-ai/deepagents","slug":"unbalanced-braces-in-model-params-value","errorCode":null,"errorMessage":"Unbalanced braces in --model-params value","messagePattern":"Unbalanced braces in --model-params value","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"libs/code/deepagents_code/app.py","lineNumber":1969,"sourceCode":"            raise ValueError(msg)\n        # Parse the quoted token with shlex so escaped quotes are unescaped.\n        json_str = shlex.split(after[: end + 1], posix=True)[0]\n        rest = after[end + 1 :].lstrip()\n    elif after[0] == \"{\":\n        # Walk forward to find the matching closing brace.\n        depth = 0\n        end = -1\n        for i, ch in enumerate(after):\n            if ch == \"{\":\n                depth += 1\n            elif ch == \"}\":\n                depth -= 1\n                if depth == 0:\n                    end = i\n                    break\n        if end == -1:\n            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):","sourceCodeStart":1951,"sourceCodeEnd":1987,"githubUrl":"https://github.com/langchain-ai/deepagents/blob/a1af029e6e73cb17c36bff823d227747b28e91e1/libs/code/deepagents_code/app.py#L1951-L1987","documentation":"When the --model-params value starts with '{', _extract_model_params_flag tracks brace depth to find the matching closing '}'. If the end of the argument is reached before depth returns to 0, it raises ValueError because the JSON object braces are unbalanced. A well-formed object must have equal opening and closing braces.","triggerScenarios":"Passing --model-params '{\"temperature\":0.2' (missing the closing brace) or a value where extra '{' without matching '}' leaves depth > 0 at end of input.","commonSituations":"Truncated paste of a multi-key JSON object; shell brace-expansion or history expansion eating characters; generating the flag from a template where the closing brace was on a dropped line; nested objects where an inner brace was forgotten.","solutions":["Balance the braces: --model-params '{\"temperature\":0.2}'.","Validate the JSON locally first, e.g. python -c 'import json,sys; json.loads(sys.argv[1])' '{...}', before passing it to the CLI.","Single-quote the whole value to prevent shell interpretation, and check nested objects have their own closing braces."],"exampleFix":"# before\ndcode --model-params '{\"temperature\":0.2\n\n# after\ndcode --model-params '{\"temperature\":0.2}'","handlingStrategy":"try-catch","validationCode":"value = raw.split(None, 1)[1].strip() if len(raw.split(None, 1)) > 1 else ''\nif value.startswith('{') and value.count('{') != value.count('}'):\n    import json\n    try:\n        json.loads(value)\n    except json.JSONDecodeError as e:\n        raise SystemExit(f\"unbalanced braces in --model-params: {e}\")","typeGuard":null,"tryCatchPattern":"try:\n    handle_command(argv)\nexcept ValueError as e:\n    if \"Unbalanced braces\" in str(e):\n        print(\"ensure the --model-params JSON object has matching braces: --model-params '{...}'\")\n        sys.exit(2)\n    raise","preventionTips":["Validate the object with json.loads before passing it on the command line.","Keep the JSON on one line inside single quotes to avoid paste/shell truncation.","For nested objects, count braces or build the string programmatically with json.dumps."],"tags":["cli","argument-parsing","json","shell"],"backgroundTag":"unbalanced-braces-json-arg","analyzedSha":"a1af029e6e73cb17c36bff823d227747b28e91e1","analyzedAt":"2026-08-29T11:43:24.718Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}