[GH-ISSUE #11444] Tool Function Parameters Schema Fields Are Being Stripped #69616

Open
opened 2026-05-04 18:39:19 -05:00 by GiteaMirror · 1 comment
Owner

Originally created by @jonigl on GitHub (Jul 16, 2025).
Original GitHub issue: https://github.com/ollama/ollama/issues/11444

Originally assigned to: @jmorganca, @ParthSareen on GitHub.

What is the issue?

Description

When using tools with complex JSON schemas, Ollama's Go backend is silently dropping important JSON schema properties due to a restrictive struct definition in ToolFunction. This causes tools that rely on advanced JSON schema features to malfunction.

Expected Behavior

Tool function parameters should preserve all valid JSON schema properties including:

  • anyOf for union types
  • const for literal values
  • additionalProperties for validation control
  • $schema for schema version
  • And other standard JSON schema keywords

Actual Behavior

Only the following fields are preserved in tool parameters:

  • type
  • $defs (mapped from defs)
  • items
  • required
  • properties

All other JSON schema properties are silently dropped.

Root Cause

The issue is in the Go struct definition for ToolFunction in Ollama's codebase:

type ToolFunction struct {
    Name        string `json:"name"`
    Description string `json:"description"`
    Parameters  struct {
        Type       string   `json:"type"`
        Defs       any      `json:"$defs,omitempty"`
        Items      any      `json:"items,omitempty"`
        Required   []string `json:"required"`
        Properties map[string]struct {
            Type        PropertyType `json:"type"`
            Items       any          `json:"items,omitempty"`
            Description string       `json:"description"`
            Enum        []any        `json:"enum,omitempty"`
        } `json:"properties"`
    } `json:"parameters"`
}

This struct only defines specific fields and doesn't allow for additional JSON schema properties.

Example

When testing Netlify MCP Server I was testing this MPC Server which has a tool function with a complex JSON schema:

Original Schema (sent to Ollama):

{
  "type": "object",
  "properties": {
    "selectSchema": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "operation": {
              "type": "string",
              "const": "get-teams"
            },
            "params": {
              "type": "object",
              "properties": {},
              "additionalProperties": false
            }
          },
          "required": ["operation", "params"],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "operation": {
              "type": "string",
              "const": "get-team"
            },
            "params": {
              "type": "object",
              "properties": {
                "teamId": {
                  "type": "string"
                }
              },
              "required": ["teamId"],
              "additionalProperties": false
            }
          },
          "required": ["operation", "params"],
          "additionalProperties": false
        }
      ]
    }
  },
  "required": ["selectSchema"],
  "additionalProperties": false,
  "$schema": "http://json-schema.org/draft-07/schema#"
}

Actual Schema (after Ollama processing):

{
  "type": "object",
  "required": ["selectSchema"],
  "properties": {
    "selectSchema": {}
  }
}

Proposed Solution

Modify the ToolFunction struct to preserve all JSON schema properties. This could be done for example by using json.RawMessage to preserve the original JSON structure for the Parameters field:

type ToolFunction struct {
    Name        string                 `json:"name"`
    Description string                 `json:"description"`
    Parameters  json.RawMessage       `json:"parameters"`
}

Impact

This issue affects any application using Ollama with tools that have complex JSON schemas, particularly:

  • MCP (Model Context Protocol) servers
  • Tools with union types (anyOf, oneOf)
  • Tools requiring strict validation (additionalProperties: false)
  • Tools using constant values (const)

Environment

  • Ollama version: 0.9.6
  • Platform: macOS 15.5 (24F74)
  • Hardware: Apple MacBook Air M1 16GB RAM

Additional Context

This issue was discovered while checking Netlify MCP Server with the MCP client for Ollama. This MCP Server tool specification relies heavily on JSON schema features that are being stripped by this limitation.

Relevant log output


OS

macOS

GPU

Apple

CPU

Apple

Ollama version

0.9.6

Originally created by @jonigl on GitHub (Jul 16, 2025). Original GitHub issue: https://github.com/ollama/ollama/issues/11444 Originally assigned to: @jmorganca, @ParthSareen on GitHub. ### What is the issue? ## Description When using tools with complex JSON schemas, Ollama's Go backend is silently dropping important JSON schema properties due to a restrictive struct definition in `ToolFunction`. This causes tools that rely on advanced JSON schema features to malfunction. ## Expected Behavior Tool function parameters should preserve all valid JSON schema properties including: - `anyOf` for union types - `const` for literal values - `additionalProperties` for validation control - `$schema` for schema version - And other standard JSON schema keywords ## Actual Behavior Only the following fields are preserved in tool parameters: - `type` - `$defs` (mapped from `defs`) - `items` - `required` - `properties` All other JSON schema properties are silently dropped. ## Root Cause The issue is in the Go struct definition for `ToolFunction` in Ollama's codebase: ```go type ToolFunction struct { Name string `json:"name"` Description string `json:"description"` Parameters struct { Type string `json:"type"` Defs any `json:"$defs,omitempty"` Items any `json:"items,omitempty"` Required []string `json:"required"` Properties map[string]struct { Type PropertyType `json:"type"` Items any `json:"items,omitempty"` Description string `json:"description"` Enum []any `json:"enum,omitempty"` } `json:"properties"` } `json:"parameters"` } ``` This struct only defines specific fields and doesn't allow for additional JSON schema properties. Example When testing Netlify MCP Server I was testing this MPC Server which has a tool function with a complex JSON schema: Original Schema (sent to Ollama): ```json { "type": "object", "properties": { "selectSchema": { "anyOf": [ { "type": "object", "properties": { "operation": { "type": "string", "const": "get-teams" }, "params": { "type": "object", "properties": {}, "additionalProperties": false } }, "required": ["operation", "params"], "additionalProperties": false }, { "type": "object", "properties": { "operation": { "type": "string", "const": "get-team" }, "params": { "type": "object", "properties": { "teamId": { "type": "string" } }, "required": ["teamId"], "additionalProperties": false } }, "required": ["operation", "params"], "additionalProperties": false } ] } }, "required": ["selectSchema"], "additionalProperties": false, "$schema": "http://json-schema.org/draft-07/schema#" } ``` Actual Schema (after Ollama processing): ```json { "type": "object", "required": ["selectSchema"], "properties": { "selectSchema": {} } } ``` ## Proposed Solution Modify the ToolFunction struct to preserve all JSON schema properties. This could be done for example by using json.RawMessage to preserve the original JSON structure for the `Parameters` field: ```go type ToolFunction struct { Name string `json:"name"` Description string `json:"description"` Parameters json.RawMessage `json:"parameters"` } ``` ## Impact This issue affects any application using Ollama with tools that have complex JSON schemas, particularly: - MCP (Model Context Protocol) servers - Tools with union types (`anyOf`, `oneOf`) - Tools requiring strict validation (`additionalProperties: false`) - Tools using constant values (`const`) ## Environment - Ollama version: 0.9.6 - Platform: macOS 15.5 (24F74) - Hardware: Apple MacBook Air M1 16GB RAM ## Additional Context This issue was discovered while checking Netlify MCP Server with the [MCP client for Ollama](https://github.com/jonigl/mcp-client-for-ollama). This MCP Server tool specification relies heavily on JSON schema features that are being stripped by this limitation. ### Relevant log output ```shell ``` ### OS macOS ### GPU Apple ### CPU Apple ### Ollama version 0.9.6
GiteaMirror added the toolsbug labels 2026-05-04 18:39:19 -05:00
Author
Owner
<!-- gh-comment-id:3081554886 --> @jonigl commented on GitHub (Jul 16, 2025): This issue is similar to: https://github.com/ollama/ollama/issues/6155 https://github.com/ollama/ollama/issues/6377 https://github.com/ollama/ollama/issues/8222 And maybe also relates to: https://github.com/ollama/ollama/issues/11075
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/ollama#69616