how can i use tools in groq models? It is giving m...
# ask-ai
a
how can i use tools in groq models? It is giving me invalid JSON
t
Thanks for reaching out, Aditya. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — I’m responding to your question about using tools with Groq models and the “invalid JSON” error. Short answer: use the OpenAI-compatible LLM helper (the
openai.LLM.with_groq()
/
openai.LLM.withGroq()
pattern) and ensure your tool definitions use a JSON Schema–compatible structure. The “invalid JSON” error usually means the tool schema or parameters aren’t serializing to valid JSON. To help you quickly, please share the following so I can diagnose the exact cause: • Whether you’re using Python or Node.js. • The exact tool definition (the JSON/schema or code) you’re passing to the session (paste the code or schema that produces the error). • The Groq model call snippet (how you create the session/LLM), e.g. your
AgentSession
/
voice.AgentSession
code. • The full error message and any stack trace you see. Common things to check while you paste that: • Tool parameters must follow JSON Schema types (strings, numbers, booleans, objects, arrays). Avoid non-serializable types or functions in the schema. • Ensure all keys/strings are quoted and there are no trailing commas or other JSON syntax errors. • Descriptions, names, and parameter metadata should not include characters that break serialization. • In Python, decorated tool functions should return JSON-serializable values (dicts/lists/primitives). • In Node.js, define
parameters
as a proper schema object (for example using
z.object(...)
) and ensure
execute
returns serializable results. If you prefer, paste the tool JSON/schema plus a minimal snippet showing how you construct the LLM session and I’ll point out the exact line that causes the invalid JSON and a corrected example. If you want, I can also provide a small working example for your language once you tell me whether you’re on Python or Node.js. Sources: Groq STT plugin guide | LiveKit Documentation | OpenAI LLM plugin guide | LiveKit Documentation | Groq LLM plugin guide | LiveKit Documentation | Large language models (LLM) overview | LiveKit Documentation | Tool definition and use | LiveKit Documentation
g
getting this error livekit.agents._exceptions.APIStatusError: Error code: 400 - {'error': {'message': "invalid JSON schema for tool end-call, tools[0].function.parameters: 'required' present but 'properties' is missing", 'type': 'invalid_request_error', 'param': 'tool end-call, tools[0].function.parameters'}} (status_code=400, request_id=req_01kh9sx547ed59y9ecc1x6spvt, body={'message': "invalid JSON schema for tool end-call, tools[0].function.parameters: 'required' present but 'properties' is missing", 'type': 'invalid_request_error', 'param': 'tool end-call, tools[0].function.parameters'}, retryable=True)
t
Thanks — I’m responding to the error about your
end-call
tool where the message says: "'required' present but 'properties' is missing." That pinpoints the problem: when a JSON Schema includes a
required
array, it must also include a
properties
object that defines those required fields. What to change (short): • If your tool needs parameters, add a
properties
object that declares each parameter (type, description, etc.), and keep your
required
list referencing names defined under
properties
. • If your tool has no parameters, remove
required
(and
properties
) entirely or declare the schema as an empty object. Examples you can copy and adapt 1) Tool with a single required parameter (Python style/schema):
Copy code
# schema you send to the LLM / plugin must include properties
{
  "type": "object",
  "properties": {
    "reason": {
      "type": "string",
      "description": "The reason for ending the call"
    }
  },
  "required": ["reason"]
}
2) Tool with optional parameters:
Copy code
{
  "type": "object",
  "properties": {
    "reason": { "type": "string" },
    "immediately": { "type": "boolean" }
  }
  # no "required" here, so both are optional
}
3) Tool with no parameters:
Copy code
{
  "type": "object"
}
Or simply omit
function.parameters
entirely if the system allows it. If you use Python decorated tools, make sure the function signature matches the schema (or omit parameters if none are needed):
Copy code
@function_tool()
async def end_call(ctx: RunContext, reason: str):
    ...
This should align with the schema that includes
reason
under
properties
. Next steps I can take for you • Paste your current
end-call
tool definition (the JSON/schema or the code). Tell me whether you're on Python or Node.js. • I’ll point out the exact lines to change and provide a corrected, ready-to-run snippet. If you paste the tool code now I’ll fix it and return the corrected schema and example usage. Sources: Tool definition and use | LiveKit Documentation