Fix: avoid empty system prompts (Perplexity Sonar 400)#137
Fix: avoid empty system prompts (Perplexity Sonar 400)#137rasulkireev wants to merge 1 commit intomainfrom
Conversation
📝 WalkthroughWalkthroughSystem prompt handling across multiple agent modules changed to return non-empty placeholder messages instead of empty strings when default conditions are met, accommodating provider requirements that reject empty system messages. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
core/agents/title_suggestions_agent.py (1)
66-111:⚠️ Potential issue | 🟠 Major
add_feedback_historycan still return an empty string — same root cause this PR fixes.When none of the feedback lists (
neutral_suggestions,liked_suggestions,disliked_suggestions) are populated,feedback_sectionsstays[]and"\n".join([])returns"". This will trigger the same Perplexity Sonar 400 error on empty system messages that this PR addresses elsewhere.Proposed fix
+ if not feedback_sections: + return "No previous title feedback was provided." + return "\n".join(feedback_sections)
Greptile OverviewGreptile SummaryThis PR addresses Perplexity Sonar’s strict validation that Changes are localized to prompt-construction utilities:
Net effect: request construction should no longer include invalid empty system prompts, preventing 400s from providers that reject them (e.g. Perplexity Sonar). Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Caller as App code
participant Agent as pydantic_ai.Agent
participant SP as @agent.system_prompt fns
participant Provider as LLM provider (Perplexity Sonar)
Caller->>Agent: create_title_suggestions_agent(...)
Agent->>SP: evaluate system prompts (incl. add_todays_date, add_user_prompt)
alt ctx.deps.user_prompt missing
SP-->>Agent: "No additional user prompt was provided."
else ctx.deps.user_prompt present
SP-->>Agent: "IMPORTANT USER REQUEST: ..."
end
Agent->>Provider: send request with system messages
Provider-->>Agent: 200 OK (system content non-empty)
Caller->>SP: add_project_pages(ctx)
alt ctx.deps.project_pages empty
SP-->>Caller: "No internal project pages were provided..."
else pages present
SP-->>Caller: "REQUIRED/OPTIONAL PAGES TO LINK..."
end
Caller->>SP: add_target_keywords(ctx)
alt ctx.deps.project_keywords empty
SP-->>Caller: "No specific SEO focus keywords were provided."
else keywords present
SP-->>Caller: "Focus Keywords for SEO..."
end
|
Additional Comments (1)
|
This fixes a Perplexity Sonar 400 error: 'system message content cannot be empty or contain only whitespace'.
Root cause: several @agent.system_prompt helper functions returned an empty string (e.g. when no project pages / no keywords / no user_prompt). Some providers reject empty system messages.
Change: return an explicit non-empty no-op instruction instead of an empty string in:
This prevents request construction from including invalid empty system messages.
Summary by CodeRabbit
Release Notes