Skip to content

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

Closed

Description

@sareiodata

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.

Activity

  1. stefkampouris commented on Jul 13, 2025

    @stefkampouris

    +1

  2. Avinier commented on Jul 13, 2025

    @Avinier

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

  3. stefkampouris commented on Jul 13, 2025

    @stefkampouris

    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

  4. JPDucky commented on Jul 13, 2025

    @JPDucky

    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.

  5. pristugm commented on Jul 13, 2025

    @pristugm

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

  6. sdeleon28 commented on Jul 14, 2025

    @sdeleon28

    getting the same with most OpenAI models

  7. self-assigned this
    on Jul 14, 2025
  8. stefkampouris commented on Jul 14, 2025

    @stefkampouris

    its fixed with the new version

  9. sevdeutsch commented on Jul 14, 2025

    @sevdeutsch

    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

  10. sareiodata commented on Jul 14, 2025

    @sareiodata
    Author

    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

  11. moziboo commented on Jul 14, 2025

    @moziboo

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

  12. sdeleon28 commented on Jul 14, 2025

    @sdeleon28

    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.

  13. nacholupotti commented on Jul 16, 2025

    @nacholupotti

    Same error than @sdeleon28 here

  14. sareiodata commented on Jul 17, 2025

    @sareiodata
    Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions