AI_InvalidToolInputError: Invalid input for tool write: Type validation failed #683

Closed
opened 2026-02-16 17:27:53 -05:00 by yindo · 13 comments
Owner

Originally created by @sareiodata on GitHub (Jul 13, 2025).

Originally assigned to: @thdxr on GitHub.

When the model tries to write a json in a json file it throws this error.

AI_InvalidToolInputError: Invalid input for tool write: Type validation failed
value:
{"filePath":"/home/proj/about.json", "content":"{"title":"about project"}"}

Error message: [
{
"code":"invalid_type",
"expected":"string",
"received":"object",
"path":["content"],
"message":"Expected string, received object. "
}
]

PS: I had to write this error message my hand, I can't copy text in the TUI and /share didn't include the error from Opencode, only get Tool execution aborted there.

Originally created by @sareiodata on GitHub (Jul 13, 2025). Originally assigned to: @thdxr on GitHub. When the model tries to write a json in a json file it throws this error. AI_InvalidToolInputError: Invalid input for tool write: Type validation failed value: {"filePath":"/home/proj/about.json", "content":"{"title":"about project"}"} Error message: [ { "code":"invalid_type", "expected":"string", "received":"object", "path":["content"], "message":"Expected string, received object. " } ] PS: I had to write this error message my hand, I can't copy text in the TUI and /share didn't include the error from Opencode, only get Tool execution aborted there.
yindo closed this issue 2026-02-16 17:27:53 -05:00
Author
Owner

@stefkampouris commented on GitHub (Jul 13, 2025):

+1

@stefkampouris commented on GitHub (Jul 13, 2025): +1
Author
Owner

@Avinier commented on GitHub (Jul 13, 2025):

tool executions do get messed up sometimes, prompting a simple 'continue' after the error does the work 99% of the times.

@Avinier commented on GitHub (Jul 13, 2025): tool executions do get messed up sometimes, prompting a simple 'continue' after the error does the work 99% of the times.
Author
Owner

@stefkampouris commented on GitHub (Jul 13, 2025):

tool executions do get messed up sometimes, prompting a simple 'continue' after the error does the work 99% of the times.

Tried it but still with kimi k2 when writing files with open router please fix it asap

@stefkampouris commented on GitHub (Jul 13, 2025): > tool executions do get messed up sometimes, prompting a simple 'continue' after the error does the work 99% of the times. Tried it but still with kimi k2 when writing files with open router please fix it asap
Author
Owner

@JPDucky commented on GitHub (Jul 13, 2025):

I can confirm that this error occurs as well with most of the openrouter models that have been released this week that I have tried (see pic).

Image

From my openrouter activity panel:

{
  "id": 15413899903,
  "generation_id": "gen-1752443640-Ldhggs2ezsmyYCAAXaMZ",
  "provider_name": "xAI",
  "model": "x-ai/grok-4-07-09",
  "app_id": 2312835,
  "external_user": null,
  "streamed": true,
  "cancelled": false,
  "generation_time": 9997,
  "latency": 8971,
  "moderation_latency": null,
  "created_at": "2025-07-13T21:54:19.758853+00:00",
  "tokens_prompt": 50677,
  "tokens_completion": 310,
  "native_tokens_prompt": 50288,
  "native_tokens_completion": 641,
  "native_tokens_reasoning": 346,
  "native_tokens_cached": 4,
  "num_media_prompt": null,
  "num_media_completion": null,
  "num_search_results": null,
  "origin": "https://opencode.ai/",
  "usage": 0.15886521,
  "finish_reason": "stop",
  "usage_cache": -0.000009,
  "usage_data": -0.00160479,
  "usage_web": null,
  "usage_file": 0,
  "byok_usage_inference": null,
  "provider_responses": [
    {
      "id": "537b66ec-dcbc-5ac2-ed82-b8603aa2bfb6",
      "endpoint_id": "d40bef9d-6936-4c57-9749-bf7399de4a77",
      "provider_name": "xAI",
      "status": 200,
      "latency": 410,
      "is_byok": false
    }
  ],
  "provider_api_key_id": null,
  "is_byok": false,
  "native_finish_reason": "stop",
  "app": {
    "id": 2312835,
    "created_at": "2025-06-17T19:38:45.470675+00:00",
    "description": null,
    "title": "OpenCode Model Validation",
    "main_url": null,
    "origin_url": "https://opencode.ai/",
    "source_code_url": null
  }
}
{
  "id": 15413784316,
  "generation_id": "gen-1752443489-DcSKpny8BJicWUXwfybM",
  "provider_name": "Google",
  "model": "google/gemini-2.5-pro",
  "app_id": 2312835,
  "external_user": null,
  "streamed": true,
  "cancelled": false,
  "generation_time": 7648,
  "latency": 7429,
  "moderation_latency": null,
  "created_at": "2025-07-13T21:51:37.298214+00:00",
  "tokens_prompt": 50645,
  "tokens_completion": 12,
  "native_tokens_prompt": 59838,
  "native_tokens_completion": 8,
  "native_tokens_reasoning": 0,
  "native_tokens_cached": 0,
  "num_media_prompt": null,
  "num_media_completion": null,
  "num_search_results": null,
  "origin": "https://opencode.ai/",
  "usage": 0.074128725,
  "finish_reason": "tool_calls",
  "usage_cache": null,
  "usage_data": -0.000748775,
  "usage_web": null,
  "usage_file": null,
  "byok_usage_inference": null,
  "provider_responses": [
    {
      "endpoint_id": "43106252-bd69-498f-84f5-1fde678783f7",
      "provider_name": "Google",
      "status": 200,
      "latency": 7429,
      "is_byok": false
    }
  ],
  "provider_api_key_id": null,
  "is_byok": false,
  "native_finish_reason": "STOP",
  "app": {
    "id": 2312835,
    "created_at": "2025-06-17T19:38:45.470675+00:00",
    "description": null,
    "title": "OpenCode Model Validation",
    "main_url": null,
    "origin_url": "https://opencode.ai/",
    "source_code_url": null
  }
}
{
  "id": 15413755784,
  "generation_id": "gen-1752443453-QbQkPmvqZSIXPGFsa14b",
  "provider_name": "Google",
  "model": "google/gemini-2.5-flash-preview-05-20",
  "app_id": 2312835,
  "external_user": null,
  "streamed": true,
  "cancelled": false,
  "generation_time": 4328,
  "latency": 1325,
  "moderation_latency": null,
  "created_at": "2025-07-13T21:50:57.639235+00:00",
  "tokens_prompt": 53636,
  "tokens_completion": 406,
  "native_tokens_prompt": 63733,
  "native_tokens_completion": 511,
  "native_tokens_reasoning": 0,
  "native_tokens_cached": 59617,
  "num_media_prompt": null,
  "num_media_completion": null,
  "num_search_results": null,
  "origin": "https://opencode.ai/",
  "usage": 0.003060972,
  "finish_reason": "tool_calls",
  "usage_cache": -0.0067069125,
  "usage_data": -0.0000986655,
  "usage_web": null,
  "usage_file": null,
  "byok_usage_inference": null,
  "provider_responses": [
    {
      "endpoint_id": "d4de9312-6c2c-4f4b-a224-4221aa29ad7d",
      "provider_name": "Google",
      "status": 200,
      "latency": 1325,
      "is_byok": false
    }
  ],
  "provider_api_key_id": null,
  "is_byok": false,
  "native_finish_reason": "STOP",
  "app": {
    "id": 2312835,
    "created_at": "2025-06-17T19:38:45.470675+00:00",
    "description": null,
    "title": "OpenCode Model Validation",
    "main_url": null,
    "origin_url": "https://opencode.ai/",
    "source_code_url": null
  }
}
{
  "id": 15413752404,
  "generation_id": "gen-1752443450-jwK2dODP2dSYdqKDgznS",
  "provider_name": "Google",
  "model": "google/gemini-2.5-flash-preview-05-20",
  "app_id": 2312835,
  "external_user": null,
  "streamed": true,
  "cancelled": false,
  "generation_time": 2076,
  "latency": 1757,
  "moderation_latency": null,
  "created_at": "2025-07-13T21:50:53.07132+00:00",
  "tokens_prompt": 50595,
  "tokens_completion": 33,
  "native_tokens_prompt": 59793,
  "native_tokens_completion": 33,
  "native_tokens_reasoning": 0,
  "native_tokens_cached": 10045,
  "num_media_prompt": null,
  "num_media_completion": null,
  "num_search_results": null,
  "origin": "https://opencode.ai/",
  "usage": 0.0077688,
  "finish_reason": "tool_calls",
  "usage_cache": -0.0011300625,
  "usage_data": -0.0000898875,
  "usage_web": null,
  "usage_file": null,
  "byok_usage_inference": null,
  "provider_responses": [
    {
      "endpoint_id": "d4de9312-6c2c-4f4b-a224-4221aa29ad7d",
      "provider_name": "Google",
      "status": 200,
      "latency": 1756,
      "is_byok": false
    }
  ],
  "provider_api_key_id": null,
  "is_byok": false,
  "native_finish_reason": "STOP",
  "app": {
    "id": 2312835,
    "created_at": "2025-06-17T19:38:45.470675+00:00",
    "description": null,
    "title": "OpenCode Model Validation",
    "main_url": null,
    "origin_url": "https://opencode.ai/",
    "source_code_url": null
  }
}
{
  "id": 15413712923,
  "generation_id": "gen-1752443398-Cuu5l6H8WAzliBv2iei6",
  "provider_name": "Google",
  "model": "google/gemini-2.5-flash-preview-05-20",
  "app_id": 2312835,
  "external_user": null,
  "streamed": true,
  "cancelled": false,
  "generation_time": 4111,
  "latency": 1287,
  "moderation_latency": null,
  "created_at": "2025-07-13T21:50:03.086949+00:00",
  "tokens_prompt": 53550,
  "tokens_completion": 241,
  "native_tokens_prompt": 63648,
  "native_tokens_completion": 308,
  "native_tokens_reasoning": 0,
  "native_tokens_cached": 0,
  "num_media_prompt": null,
  "num_media_completion": null,
  "num_search_results": null,
  "origin": "https://opencode.ai/",
  "usage": 0.00963468,
  "finish_reason": "stop",
  "usage_cache": null,
  "usage_data": -0.00009732,
  "usage_web": null,
  "usage_file": null,
  "byok_usage_inference": null,
  "provider_responses": [
    {
      "endpoint_id": "d4de9312-6c2c-4f4b-a224-4221aa29ad7d",
      "provider_name": "Google",
      "status": 200,
      "latency": 1287,
      "is_byok": false
    }
  ],
  "provider_api_key_id": null,
  "is_byok": false,
  "native_finish_reason": "MALFORMED_FUNCTION_CALL",
  "app": {
    "id": 2312835,
    "created_at": "2025-06-17T19:38:45.470675+00:00",
    "description": null,
    "title": "OpenCode Model Validation",
    "main_url": null,
    "origin_url": "https://opencode.ai/",
    "source_code_url": null
  }
}

Let me know what other information I can provide that may be helpful.

@JPDucky commented on GitHub (Jul 13, 2025): I can confirm that this error occurs as well with most of the openrouter models that have been released this week that I have tried (see pic). <img width="1309" height="340" alt="Image" src="https://github.com/user-attachments/assets/94c7ec1a-7d85-4703-b5e2-114437853309" /> From my openrouter activity panel: ``` { "id": 15413899903, "generation_id": "gen-1752443640-Ldhggs2ezsmyYCAAXaMZ", "provider_name": "xAI", "model": "x-ai/grok-4-07-09", "app_id": 2312835, "external_user": null, "streamed": true, "cancelled": false, "generation_time": 9997, "latency": 8971, "moderation_latency": null, "created_at": "2025-07-13T21:54:19.758853+00:00", "tokens_prompt": 50677, "tokens_completion": 310, "native_tokens_prompt": 50288, "native_tokens_completion": 641, "native_tokens_reasoning": 346, "native_tokens_cached": 4, "num_media_prompt": null, "num_media_completion": null, "num_search_results": null, "origin": "https://opencode.ai/", "usage": 0.15886521, "finish_reason": "stop", "usage_cache": -0.000009, "usage_data": -0.00160479, "usage_web": null, "usage_file": 0, "byok_usage_inference": null, "provider_responses": [ { "id": "537b66ec-dcbc-5ac2-ed82-b8603aa2bfb6", "endpoint_id": "d40bef9d-6936-4c57-9749-bf7399de4a77", "provider_name": "xAI", "status": 200, "latency": 410, "is_byok": false } ], "provider_api_key_id": null, "is_byok": false, "native_finish_reason": "stop", "app": { "id": 2312835, "created_at": "2025-06-17T19:38:45.470675+00:00", "description": null, "title": "OpenCode Model Validation", "main_url": null, "origin_url": "https://opencode.ai/", "source_code_url": null } } ``` ``` { "id": 15413784316, "generation_id": "gen-1752443489-DcSKpny8BJicWUXwfybM", "provider_name": "Google", "model": "google/gemini-2.5-pro", "app_id": 2312835, "external_user": null, "streamed": true, "cancelled": false, "generation_time": 7648, "latency": 7429, "moderation_latency": null, "created_at": "2025-07-13T21:51:37.298214+00:00", "tokens_prompt": 50645, "tokens_completion": 12, "native_tokens_prompt": 59838, "native_tokens_completion": 8, "native_tokens_reasoning": 0, "native_tokens_cached": 0, "num_media_prompt": null, "num_media_completion": null, "num_search_results": null, "origin": "https://opencode.ai/", "usage": 0.074128725, "finish_reason": "tool_calls", "usage_cache": null, "usage_data": -0.000748775, "usage_web": null, "usage_file": null, "byok_usage_inference": null, "provider_responses": [ { "endpoint_id": "43106252-bd69-498f-84f5-1fde678783f7", "provider_name": "Google", "status": 200, "latency": 7429, "is_byok": false } ], "provider_api_key_id": null, "is_byok": false, "native_finish_reason": "STOP", "app": { "id": 2312835, "created_at": "2025-06-17T19:38:45.470675+00:00", "description": null, "title": "OpenCode Model Validation", "main_url": null, "origin_url": "https://opencode.ai/", "source_code_url": null } } ``` ``` { "id": 15413755784, "generation_id": "gen-1752443453-QbQkPmvqZSIXPGFsa14b", "provider_name": "Google", "model": "google/gemini-2.5-flash-preview-05-20", "app_id": 2312835, "external_user": null, "streamed": true, "cancelled": false, "generation_time": 4328, "latency": 1325, "moderation_latency": null, "created_at": "2025-07-13T21:50:57.639235+00:00", "tokens_prompt": 53636, "tokens_completion": 406, "native_tokens_prompt": 63733, "native_tokens_completion": 511, "native_tokens_reasoning": 0, "native_tokens_cached": 59617, "num_media_prompt": null, "num_media_completion": null, "num_search_results": null, "origin": "https://opencode.ai/", "usage": 0.003060972, "finish_reason": "tool_calls", "usage_cache": -0.0067069125, "usage_data": -0.0000986655, "usage_web": null, "usage_file": null, "byok_usage_inference": null, "provider_responses": [ { "endpoint_id": "d4de9312-6c2c-4f4b-a224-4221aa29ad7d", "provider_name": "Google", "status": 200, "latency": 1325, "is_byok": false } ], "provider_api_key_id": null, "is_byok": false, "native_finish_reason": "STOP", "app": { "id": 2312835, "created_at": "2025-06-17T19:38:45.470675+00:00", "description": null, "title": "OpenCode Model Validation", "main_url": null, "origin_url": "https://opencode.ai/", "source_code_url": null } } ``` ``` { "id": 15413752404, "generation_id": "gen-1752443450-jwK2dODP2dSYdqKDgznS", "provider_name": "Google", "model": "google/gemini-2.5-flash-preview-05-20", "app_id": 2312835, "external_user": null, "streamed": true, "cancelled": false, "generation_time": 2076, "latency": 1757, "moderation_latency": null, "created_at": "2025-07-13T21:50:53.07132+00:00", "tokens_prompt": 50595, "tokens_completion": 33, "native_tokens_prompt": 59793, "native_tokens_completion": 33, "native_tokens_reasoning": 0, "native_tokens_cached": 10045, "num_media_prompt": null, "num_media_completion": null, "num_search_results": null, "origin": "https://opencode.ai/", "usage": 0.0077688, "finish_reason": "tool_calls", "usage_cache": -0.0011300625, "usage_data": -0.0000898875, "usage_web": null, "usage_file": null, "byok_usage_inference": null, "provider_responses": [ { "endpoint_id": "d4de9312-6c2c-4f4b-a224-4221aa29ad7d", "provider_name": "Google", "status": 200, "latency": 1756, "is_byok": false } ], "provider_api_key_id": null, "is_byok": false, "native_finish_reason": "STOP", "app": { "id": 2312835, "created_at": "2025-06-17T19:38:45.470675+00:00", "description": null, "title": "OpenCode Model Validation", "main_url": null, "origin_url": "https://opencode.ai/", "source_code_url": null } } ``` ``` { "id": 15413712923, "generation_id": "gen-1752443398-Cuu5l6H8WAzliBv2iei6", "provider_name": "Google", "model": "google/gemini-2.5-flash-preview-05-20", "app_id": 2312835, "external_user": null, "streamed": true, "cancelled": false, "generation_time": 4111, "latency": 1287, "moderation_latency": null, "created_at": "2025-07-13T21:50:03.086949+00:00", "tokens_prompt": 53550, "tokens_completion": 241, "native_tokens_prompt": 63648, "native_tokens_completion": 308, "native_tokens_reasoning": 0, "native_tokens_cached": 0, "num_media_prompt": null, "num_media_completion": null, "num_search_results": null, "origin": "https://opencode.ai/", "usage": 0.00963468, "finish_reason": "stop", "usage_cache": null, "usage_data": -0.00009732, "usage_web": null, "usage_file": null, "byok_usage_inference": null, "provider_responses": [ { "endpoint_id": "d4de9312-6c2c-4f4b-a224-4221aa29ad7d", "provider_name": "Google", "status": 200, "latency": 1287, "is_byok": false } ], "provider_api_key_id": null, "is_byok": false, "native_finish_reason": "MALFORMED_FUNCTION_CALL", "app": { "id": 2312835, "created_at": "2025-06-17T19:38:45.470675+00:00", "description": null, "title": "OpenCode Model Validation", "main_url": null, "origin_url": "https://opencode.ai/", "source_code_url": null } } ``` Let me know what other information I can provide that may be helpful.
Author
Owner

@pristugm commented on GitHub (Jul 13, 2025):

@thdxr Kimi is turning out to be a claude tier agent model and 80% cheaper, please make it usable!!

@pristugm commented on GitHub (Jul 13, 2025): @thdxr Kimi is turning out to be a claude tier agent model and 80% cheaper, please make it usable!!
Author
Owner

@sdeleon28 commented on GitHub (Jul 13, 2025):

getting the same with most OpenAI models

@sdeleon28 commented on GitHub (Jul 13, 2025): getting the same with most OpenAI models
Author
Owner

@stefkampouris commented on GitHub (Jul 14, 2025):

its fixed with the new version

@stefkampouris commented on GitHub (Jul 14, 2025): its fixed with the new version
Author
Owner

@sevdeutsch commented on GitHub (Jul 14, 2025):

I get the same error with v0.3.2. using Gemini 2.0 Flash via open router.
The weird thing is that it actually completes the task as expected ("Create a test.md with "Hello World" as content") but it throws the "Tool execution aborted" consistently

@sevdeutsch commented on GitHub (Jul 14, 2025): I get the same error with v0.3.2. using Gemini 2.0 Flash via open router. The weird thing is that it actually completes the task as expected ("Create a test.md with "Hello World" as content") but it throws the "Tool execution aborted" consistently
Author
Owner

@sareiodata commented on GitHub (Jul 14, 2025):

Can confirm this exact error is fixed in the latest version. It can write json inside json files now.

I'm using it with mistralai/devstral-small-2507

@sareiodata commented on GitHub (Jul 14, 2025): Can confirm this exact error is fixed in the latest version. It can write json inside json files now. I'm using it with mistralai/devstral-small-2507
Author
Owner

@moziboo commented on GitHub (Jul 14, 2025):

I'm still getting this when using OpenRouter and it needs to run a git command. Is that a new issue? v0.3.5

@moziboo commented on GitHub (Jul 14, 2025): I'm still getting this when using OpenRouter and it needs to run a git command. Is that a new issue? v0.3.5
Author
Owner

@sdeleon28 commented on GitHub (Jul 14, 2025):

Still happenning pretty much all the time in 0.3.5.

Image

Most of the errors are about replaceAll and timeout.

@thdxr / @sareiodata can you re-open?

P.S.: FWIW it's not the model, codex succeeds to act on the same exact prompts in the same exact codebase.

@sdeleon28 commented on GitHub (Jul 14, 2025): Still happenning pretty much all the time in 0.3.5. <img width="406" height="263" alt="Image" src="https://github.com/user-attachments/assets/53009bf7-259f-48de-9960-98519c31b817" /> Most of the errors are about `replaceAll` and `timeout`. @thdxr / @sareiodata can you re-open? P.S.: FWIW it's not the model, `codex` succeeds to act on the same exact prompts in the same exact codebase.
Author
Owner

@nacholupotti commented on GitHub (Jul 16, 2025):

Same error than @sdeleon28 here

@nacholupotti commented on GitHub (Jul 16, 2025): Same error than @sdeleon28 here
Author
Owner

@sareiodata commented on GitHub (Jul 17, 2025):

Both seam to be individual issues, not related to this. The error messages are different.

@sareiodata commented on GitHub (Jul 17, 2025): Both seam to be individual issues, not related to this. The error messages are different.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#683