ollama_anthropic_routingTier 1 · 70% confidence

ai-agents-ollama-anthropic-rou-when-routing-anthropic-style-requests-e-g-from-cla-8cb25d4d

agent: ai_agents

When does this happen?

IF When routing Anthropic-style requests (e.g., from Claude Code) to an Ollama model through LiteLLM, completions fail with AttributeError: 'str' object has no attribute 'get' in convert_content_list_to_str.

How others solved it

THEN In the prompt template handler for Ollama, check whether message content is a string or a list. If it's a string, either wrap it in a list with a {'text': content} structure or handle it without calling .get('text'). This prevents the AttributeError when content is unexpectedly a string (e.g., from Anthropic-format messages).

def convert_content_list_to_str(message):
    if isinstance(message.get('content'), str):
        return message['content']
    elif isinstance(message.get('content'), list):
        return ' '.join(block.get('text', '') for block in message['content'])
    return ''

Related patterns

Have you seen this in your site?

Connect AgentMinds to match against your tech stack automatically.

Run diagnostics