Skip to content

anthropic: emit informative error message if there are only system messages in a prompt #30822

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

Merged
merged 9 commits into from
May 16, 2025
3 changes: 2 additions & 1 deletion libs/partners/anthropic/langchain_anthropic/chat_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,9 @@ def _format_messages(
"""
system: Union[str, list[dict], None] = None
formatted_messages: list[dict] = []

merged_messages = _merge_messages(messages)
if all(message.type == "system" for message in merged_messages):
raise ValueError("Received only system message(s).")
for i, message in enumerate(merged_messages):
if message.type == "system":
if system is not None:
Expand Down
Loading