Skip to content

fastcore.tools.view() generates OpenAI-incompatible tool schema for view_range #798

@bobrowadam

Description

@bobrowadam

Description

fastcore.tools.view() currently declares:

view_range: tuple[int, int] = None

When this is turned into a tool schema via toolslm.funccall.get_schema(), the generated JSON Schema for view_range uses prefixItems without items.

That works for some consumers, but OpenAI rejects it with:

Invalid schema for function 'view': In context=('properties', 'view_range'), array schema missing items.

This breaks downstream tools that expose fastcore.tools.view directly as an OpenAI function/tool, including shell-sage when configured to use OpenAI models.

Reproduction

Environment:

  • macOS
  • shell-sage 1.0.6
  • fastcore 1.12.33
  • also reproduced by inspecting latest fastcore 1.12.34 source on PyPI

Minimal repro:

from toolslm.funccall import get_schema
from fastcore.tools import view
import json

print(json.dumps(get_schema(view, pname="parameters"), indent=2))

Generated schema includes:

"view_range": {
  "type": "array",
  "default": null,
  "prefixItems": [
    {"type": "integer"},
    {"type": "integer"}
  ]
}

OpenAI then rejects the tool schema with:

Invalid schema for function 'view': In context=('properties', 'view_range'), array schema missing items.

Expected

The generated schema should be accepted by OpenAI function/tool calling.

Actual

The generated schema is rejected by OpenAI because the array schema has prefixItems but no items.

Local workaround

Changing the signature to:

view_range: list[int] = None

produces:

"view_range": {
  "type": "array",
  "items": {"type": "integer"},
  "default": null
}

and fixes the issue for OpenAI-backed shell-sage.

Suggested fix

Either:

  1. change view_range in fastcore.tools.view() from tuple[int, int] to list[int], or
  2. update the schema generator so tuple schemas emitted for OpenAI-compatible tool calling also include a valid items field.

I’m happy to test a fix against shell-sage + OpenAI.

Metadata

Metadata

Assignees

No one assigned

    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