Initial Checks
Description
When using the Groq API with the qwen-qwq-32b model and tool calling, I'm experiencing intermittent 400 errors (Bad Request). These errors occur approximately 1 out of every 3-4 identical API calls, making the behavior inconsistent and difficult to debug.
pydantic_ai.exceptions.ModelHTTPError: status_code: 400, model_name: qwen-qwq-32b, body: {'error': {'message': "Failed to call a function. Please adjust your prompt. See 'failed_generation' for more details.", 'type': 'invalid_request_error', 'code': 'tool_use_failed', 'failed_generation': "Elon Musk's contact information is present in our database. His email address is elon.musk@example.com."}}
Example Code
import random
from dotenv import load_dotenv
from pydantic_ai import Agent
from pydantic import BaseModel
load_dotenv()
class FinalResult(BaseModel):
final_answer: str
model = "groq:qwen-qwq-32b"
agent = Agent(
model,
deps_type=str,
system_prompt=("You're helpful AI assistant."),
result_type=FinalResult,
)
@agent.tool_plain
def roll_dice() -> str:
"""Roll a six-sided die and return the result."""
return str(random.randint(1, 6))
@agent.tool_plain
def get_all_contacts() -> str:
"""Get all contacts"""
all_contacts = [
{"first_name": "John", "last_name": "Smith", "email": "john@example.com"},
{"first_name": "Jane", "last_name": "Smith", "email": "jane@example.com"},
{"first_name": "Elon", "last_name": "Musk", "email": "elon.musk@example.com"},
]
return all_contacts
task = "Can you check our database and see if we have Elon Musk contact data?"
result = agent.run_sync(task)
print(result)
print(result.data)
Python, Pydantic AI & LLM client version
Python 3.12.3
pydantic-ai==0.0.43
qwen-qwq-32b
Initial Checks
Description
When using the Groq API with the qwen-qwq-32b model and tool calling, I'm experiencing intermittent 400 errors (Bad Request). These errors occur approximately 1 out of every 3-4 identical API calls, making the behavior inconsistent and difficult to debug.
pydantic_ai.exceptions.ModelHTTPError: status_code: 400, model_name: qwen-qwq-32b, body: {'error': {'message': "Failed to call a function. Please adjust your prompt. See 'failed_generation' for more details.", 'type': 'invalid_request_error', 'code': 'tool_use_failed', 'failed_generation': "Elon Musk's contact information is present in our database. His email address is elon.musk@example.com."}}Example Code
Python, Pydantic AI & LLM client version