fix: omit empty system_prompt to avoid Anthropic API rejection#1
Open
fix: omit empty system_prompt to avoid Anthropic API rejection#1
Conversation
Anthropic's API rejects messages with `{'role': 'system', 'content': ''}`.
When no system prompt is provided, the code was passing `system_prompt=""`
to PydanticAI Agent, which translated to an empty system message.
This caused all LLM calls without an explicit system prompt (e.g.
`detect_base_urls`) to fail with a 400 error when routed through
LiteLLM to any Anthropic model (claude-opus, claude-sonnet, claude-haiku).
The fix omits the `system_prompt` kwarg entirely when there is no system
prompt, so PydanticAI never generates a system message.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
{'role': 'system', 'content': ''}— unlike OpenAI which silently accepts itConversation._run()was passingsystem_prompt=""to PydanticAI'sAgent, which generated an empty system messagedetect_base_urls) to fail with a 400 error when routed through LiteLLM to any Claude modelsystem_promptkwarg entirely when there is no system prompt to sendReproduction
Fails with:
Test plan
spectral auth extracton an app with captured traces — should no longer crash🤖 Generated with Claude Code