Skip to content

fix: omit empty system_prompt to avoid Anthropic API rejection#1

Open
hiboute wants to merge 1 commit intomainfrom
fix/empty-system-prompt
Open

fix: omit empty system_prompt to avoid Anthropic API rejection#1
hiboute wants to merge 1 commit intomainfrom
fix/empty-system-prompt

Conversation

@hiboute
Copy link
Owner

@hiboute hiboute commented Mar 17, 2026

Summary

  • Anthropic's API rejects {'role': 'system', 'content': ''} — unlike OpenAI which silently accepts it
  • When no system prompt is provided, Conversation._run() was passing system_prompt="" to PydanticAI's Agent, which generated 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 Claude model
  • The fix omits the system_prompt kwarg entirely when there is no system prompt to send

Reproduction

spectral auth extract <any-app>

Fails with:

litellm.BadRequestError: AnthropicException - Invalid Message passed in {'role': 'system', 'content': ''}

Test plan

  • Run spectral auth extract on an app with captured traces — should no longer crash
  • Run a command that uses an explicit system prompt — should still work as before

🤖 Generated with Claude Code

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant