Skip to content

fix(kimi_k25): emit JSON literals for bool/null in tool schema rendering#55

Open
zafstojano wants to merge 1 commit into
PrimeIntellect-ai:mainfrom
zafstojano:fix/kimi-k25-tool-rendering
Open

fix(kimi_k25): emit JSON literals for bool/null in tool schema rendering#55
zafstojano wants to merge 1 commit into
PrimeIntellect-ai:mainfrom
zafstojano:fix/kimi-k25-tool-rendering

Conversation

@zafstojano
Copy link
Copy Markdown

@zafstojano zafstojano commented May 19, 2026

Summary

Two cosmetic bugs in renderers/kimi_k25.py caused the TypeScript-style tool renderer to leak Python literals (True / False / None) into output that is advertised as TypeScript. Both share the same root cause: Python's str() / repr() produce capitalized literals where JSON / TS expect lower-case (true / false / null).

  • _EnumType.to_typescript_style fell through to str(e) for non-string enum members, so null / true / false enum values rendered as None / True / False.
  • _TypedParam.to_typescript_style routed numeric and boolean defaults through repr(), which is correct for ints/floats but wrong for bools (repr(True) == "True").

Fix

Route everything through json.dumps, which already produces correct JSON / TS-compatible syntax for ints, floats, bools, None, strings, lists, and dicts. The string branch in _EnumType is kept as-is to preserve the existing quoting style.

Minimal Example for Repro

from renderers.kimi_k25 import _function_to_typescript


# Bug 1: boolean default rendered as `True` instead of `true`
print(
    _function_to_typescript(
        {
            "name": "set_logging",
            "description": "Configure logging.",
            "parameters": {
                "type": "object",
                "properties": {
                    "verbose": {
                        "type": "boolean",
                        "description": "Print extra logs",
                        "default": True,
                    },
                    "quiet": {
                        "type": "boolean",
                        "description": "Suppress output",
                        "default": False,
                    },
                },
            },
        }
    )
)

print()

# Bug 2: null / bool enum members rendered as `None` / `True` / `False`
print(
    _function_to_typescript(
        {
            "name": "set_mode",
            "description": "Set a tri-state mode.",
            "parameters": {
                "type": "object",
                "properties": {
                    "mode": {
                        "description": "Mode discriminator",
                        "enum": ["auto", None, True, False, 0],
                    },
                },
            },
        }
    )
)

Before

// Configure logging.
type set_logging = (_: {
  // Suppress output
  // Default: False     <--- False is Pythonic, should be false
  quiet?: boolean,
  // Print extra logs
  // Default: True      <--- True is Pythonic, should be true
  verbose?: boolean
}) => any;

// Set a tri-state mode.
type set_mode = (_: {
  // Mode discriminator
  mode?: "auto" | None | True | False | 0   <--- Similarly as above, with None -> null
}) => any;

After

// Configure logging.
type set_logging = (_: {
  // Suppress output
  // Default: false
  quiet?: boolean,
  // Print extra logs
  // Default: true
  verbose?: boolean
}) => any;

// Set a tri-state mode.
type set_mode = (_: {
  // Mode discriminator
  mode?: "auto" | null | true | false | 0
}) => any;

Note

Low Risk
Low risk: small, localized formatting change to tool schema TypeScript string rendering; behavior only affects emitted declarations, not parsing or model I/O.

Overview
Fixes Kimi K2.5 TypeScript-style tool schema output so non-string enum values and parameter defaults are always rendered via json.dumps, producing true/false/null instead of Python True/False/None.

This changes _EnumType.to_typescript_style and _TypedParam.to_typescript_style to consistently emit JSON literals for booleans/null (and other non-string values) in generated tool declarations.

Reviewed by Cursor Bugbot for commit 9e1d2c4. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Fix bool/null rendering in Kimi K2.5 tool schema to emit JSON literals instead of Python repr

In kimi_k25.py, enum values and parameter defaults were serialized using Python's str()/repr(), producing Python-specific output like True/False/None instead of valid JSON literals true/false/null. Both _EnumType.to_typescript_style and _TypedParam.to_typescript_style now use json.dumps() for all non-string values.

Macroscope summarized 9e1d2c4.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant