Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
Back to tool/Back to issues
#518·trae-agent

[Bug]: JSONEditTool rejects the null pretty_print that its own OpenAI schema requires

Author: sxh313Created Sep 28, 2026Updated Sep 28, 2026

What happened?

JSONEditTool fails the whole call — for view, set, add and remove — when the caller sends the null for pretty_print that the tool's own OpenAI schema asks for.

Tool.get_input_schema() (trae_agent/tools/base.py:142-151) turns every optional parameter into a required, nullable one when the provider is openai:

python
# For OpenAI strict mode, all params must be in 'required'.
# Optional params are made "nullable" to be compliant.
if self.model_provider == "openai":
    required.append(param.name)
    if not param.required:
        ...
        param_schema["type"] = [current_type, "null"]

So an OpenAI-backed agent is forced to send pretty_print and is told null is legal. But the reader at trae_agent/tools/json_edit_tool.py:116 is:

python
pretty_print_arg = arguments.get("pretty_print", True)
if not isinstance(pretty_print_arg, bool):
    return ToolExecResult(error="pretty_print parameter must be a boolean.", error_code=-1)

dict.get(key, default) only returns the default when the key is absent — a present key holding null returns None, which fails the isinstance check. So the value the schema invites is the value the tool rejects, and the model has no way to reach the documented default ("Defaults to true.") except by guessing to send true.

Measured at main = e839e55 (trae_agent/tools/json_edit_tool.py blob 71c8d5126bb1b66e21512dab739a91ba6289a80b), no network and no API key needed:

required: ['operation', 'file_path', 'json_path', 'value', 'pretty_print']
pretty_print: {'type': ['boolean', 'null'], 'description': 'Whether to format the JSON output with proper indentation. Defaults to true.'}
json_path: {'type': ['string', 'null'], ...}
value: {'type': ['object', 'null'], ...}
view, pretty_print omitted   error_code=0 error=None multiline=True len=145
view, pretty_print=true      error_code=0 error=None multiline=True len=145
view, pretty_print=null      error_code=-1 error='pretty_print parameter must be a boolean.' multiline=False len=0
view, pretty_print=false     error_code=0 error=None multiline=True len=119
set, pretty_print=null       error_code=-1 error='pretty_print parameter must be a boolean.' multiline=False len=0
plain required: ['operation', 'file_path']
plain pretty_print: {'type': 'boolean', ...}

The last two rows are the contrast that makes it a provider bug rather than a tool bug: for a non-openai provider pretty_print is optional and non-nullable, so the model can simply omit it and the default works. Only the OpenAI path is broken, and it is broken for every operation that reads the argument — set/add/remove additionally lose their write.

Minimal reproduction:

python
import asyncio
import json
import tempfile
from pathlib import Path

from trae_agent.tools.base import ToolCallArguments
from trae_agent.tools.json_edit_tool import JSONEditTool


async def main():
    tool = JSONEditTool(model_provider="openai")
    print("required:", tool.get_input_schema()["required"])
    print("pretty_print:", tool.get_input_schema()["properties"]["pretty_print"])
    with tempfile.TemporaryDirectory() as directory:
        path = Path(directory) / "data.json"
        path.write_text(json.dumps({"config": {"enabled": True}}), encoding="utf-8")
        for label, extra in (
            ("omitted", {}),
            ("null", {"pretty_print": None}),
            ("true", {"pretty_print": True}),
        ):
            args = {"operation": "view", "file_path": str(path)}
            args.update(extra)
            result = await tool.execute(ToolCallArguments(args))
            print(f"{label:8s} error_code={result.error_code} error={result.error!r}")


asyncio.run(main())

What did you expect to happen?

pretty_print omitted or null should both give the documented default (true), because null is the value the generated schema puts in required for "the caller has no preference". A value that is neither true nor false should keep erroring — the existing isinstance check is the repo convention for boolean tool parameters (sequential_thinking_tool.py:176-180 is the other instance) and should stay.

Traceback

No traceback. The failure is a clean error_code=-1 return, which the agent sees as a tool error it has to work around — it just cannot know that the schema it was handed is what caused it.

What is your system, Python, dependency version?

  • OS: Windows 11 (10.0.26200)
  • Python: 3.12.13
  • trae-agent at main = e839e559ac61bdd0e057c375dd1dee391fee797d

Additional information that you believe is relevant to this bug

  • The schema-level nullable trick comes from #175 ("Adapt tool schema generation for strict API validation"); this is the reader that never followed it.
  • ckg_tool.py:100 had the same mismatch one step earlier in the same argument family, reported in #516 and fixed in #517 — there the null silently inverted the default; here it errors. Both come from one producer change and unread consumers.
  • #459 changes the adjacent line (json_edit_tool.py:132, if value is None: → if "value" not in arguments:) for the value parameter. It does not touch pretty_print, so pretty_print=null stays broken even after #459 merges. git merge-tree --write-tree between #459's head and my branch is clean (8165bd31c42d4829d3a49735472f5b413606f32f), and #459 adds its tests to tests/tools/test_json_edit_tool.py while mine land in a new file.
  • Of the four parameters the OpenAI schema makes required, json_path already tolerates null (line 111, if json_path_arg is not None and not isinstance(...)), value rejects it at line 132 — which is exactly what #459 changes — and pretty_print rejects it at line 117, which nothing else addresses.
  • I am not changing get_input_schema(): making pretty_print non-nullable would fix the OpenAI path by breaking the uniform rule the strict-mode trick depends on, and null would still be what a ToolCallArguments-level caller sends.
  • I'd like to take this and send a PR with a regression test.

Source: bytedance/trae-agent

View original on GitHubView discussion on GitHub