Skip to content

strict` mode on function call is currently not supported for grok models #1846

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
2 tasks done
Tracked by #1842
Luca-Blight opened this issue May 28, 2025 · 5 comments
Closed
2 tasks done
Tracked by #1842
Assignees

Comments

@Luca-Blight
Copy link

Initial Checks

Description

Any ideas how to work around this? Works for mistral okay.

500: Unexpected error: 500: Error processing AI query: 500: Error running data analyst: status_code: 400, model_name: grok-3-mini-fast-latest, body: Invalid request content: strict mode on function call is currently not supported.

Example Code

Python, Pydantic AI & LLM client version

python version is 3.12
pydantic-ai version is 0.2.10
LLM client is xai and model is 'grok-3-latest'(tried other models)
@DouweM
Copy link
Contributor

DouweM commented May 28, 2025

@Luca-Blight I'm working on fixing exactly this class of issues in #1835 and #1842! Can you verify you're currently doing exactly what's in https://ai.pydantic.dev/models/openai/#grok-xai, with OpenAIModel and OpenAIProvider with custom base_url? In the first PR I'm fixing it for that scenario, and in the second PR there's a new GrokProvider that'll also get this behavior.

@Luca-Blight
Copy link
Author

That's great to hear! Here's the code i'm working with, it appears correct based on the docs.

		provider = OpenAIProvider(
			api_key=config.secrets.get("GROK_API_KEY"),
			base_url="https://api.x.ai/v1",
			http_client=httpx.AsyncClient(),
		)
		model = OpenAIModel(
			model_name,
			provider=provider,
		)

switched to mistral for now, so it seems to be particular to grok.

@akarca
Copy link

akarca commented Jun 1, 2025

I solved it using pydantic-ai==0.2.12 and the code below @Luca-Blight

model = OpenAIModel(
        "grok-3",
        provider=OpenAIProvider(
            api_key="***",
            base_url="https://api.x.ai/v1",
        ),
)
model.profile.openai_supports_strict_tool_definition = False  # This line fixes

@Luca-Blight
Copy link
Author

@akarca thanks for sharing! Seems like a simple bug to fix.

@DouweM
Copy link
Contributor

DouweM commented Jun 2, 2025

@Luca-Blight @akarca If you use the new GrokProvider this should work automatically!

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

No branches or pull requests

3 participants