Skip to content

function_tool generates invalid schema for parameterless functions (Groq compatibility) #4610

@robertvy

Description

@robertvy

Description

When using function_tool decorator on a function with no parameters, the generated JSON schema is rejected by Groq's API (and potentially other strict OpenAI-compatible APIs).

Error Messages

First error:

Invalid schema for function 'django_health': In context=('properties', 'kwargs'), 
schema must have a 'type' key.

After removing **kwargs:

invalid JSON schema for tool django_health, tools[4].function.parameters: 
'required' present but 'properties' is missing

Root Cause

Groq (and other strict OpenAI-compatible APIs) require this structure even for parameterless tools:

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

But function_tool generates an incomplete schema missing type and/or properties when there are no parameters.

Reproduction

from livekit.agents import function_tool

@function_tool(name="health_check", description="Check system health")
async def health_check() -> str:
    return "OK"

# Use with Groq LLM - will fail with schema error

Workaround

Use the raw_schema parameter to explicitly define the schema for parameterless functions:

from livekit.agents import function_tool

async def health_check(raw_arguments: dict) -> str:
    return "OK"

raw_schema = {
    "name": "health_check",
    "description": "Check system health",
    "parameters": {
        "type": "object",
        "properties": {},
        "required": [],
    },
}

tool = function_tool(raw_schema=raw_schema)(health_check)

This bypasses the automatic schema generation and provides the exact JSON schema that Groq requires.

Note: When using raw_schema, the function receives parameters via a raw_arguments: dict parameter instead of individual arguments.

Expected Behavior

function_tool should generate valid JSON schemas for parameterless functions that work with all LLM providers, including Groq.

Environment

  • livekit-agents version: latest
  • LLM: Groq (via livekit.plugins.groq or OpenAI-compatible endpoint)
  • Python: 3.13

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