FG
💻 Software🤖 AI & LLMsAnthropic

Iterable vs List in the request datatypes

Freshover 1 year ago
Mar 14, 20260 views
Confidence Score85%
85%

Problem

Consider the definition of `MessageParam`: [code block] The `Iterable` here doesn't allow me to write any kind of useful transformations over the datatype without changing its state in the process: [code block] which is quite inconvenient and could easily lead to all kind of errors. Is there any reason to use `Iterable` here and in other request/response datatypes? Could it be replaced with `List`?

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Moderate Confidence Fix
84% confidence100% success rate2 verificationsLast verified Mar 14, 2026

Solution: Iterable vs List in the request datatypes

Low Risk

> Namely it'd also be a breaking change so if we do decide to change to Sequence it likely won't be shipped quickly unfortunately as some users may be relying on just being able to pass an iterable. I feel the pain of breaking changes. I wonder which use cases warrant the generality of iterable though... > Maybe a workaround for now would be to add a pydantic post-validator that turns content in

84

Trust Score

2 verifications

100% success
  1. 1

    > Namely it'd also be a breaking change so if we do decide to change to Sequence

    > Namely it'd also be a breaking change so if we do decide to change to Sequence it likely won't be shipped quickly unfortunately as some users may be relying on just being able to pass an iterable.

  2. 2

    I feel the pain of breaking changes.

    I wonder which use cases warrant the generality of iterable though...

  3. 3

    > Maybe a workaround for now would be to add a pydantic post-validator that turn

    > Maybe a workaround for now would be to add a pydantic post-validator that turns content into a list so you don't have to handle the conversion everywhere? Sorry this is difficult!

  4. 4

    No worries, I've switched to `dataclasses`. Pydantic was an overkill in my case

    No worries, I've switched to `dataclasses`. Pydantic was an overkill in my case anyway.

Validation

Resolved in anthropics/anthropic-sdk-python GitHub issue #656. Community reactions: 1 upvotes.

Verification Summary

Worked: 2
Last verified Mar 14, 2026

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

claudeanthropicllmapiquestion