chilly-france-44439
09/22/2025, 3:40 PMSecretStr in LLM.. It has been creating too much special cases for us (e.g., model_dump vs model_dump_with_secrets), any concerns about this?chilly-france-44439
09/22/2025, 3:41 PMchilly-france-44439
09/22/2025, 3:41 PMquick-window-91705
09/22/2025, 3:42 PMmodel_dump(context={'expose_secrets': True})
This is the built in pydantic support. imho we should get rid of custom methods like model_dump_with_secretschilly-france-44439
09/22/2025, 3:44 PMquick-window-91705
09/22/2025, 3:45 PMmodel_dump_json rn
Its a two word change to support it for model_dump as well
I haven't ripped out the custom methods we have rn though, should be quick
@nutritious-balloon-65098 read the LLM class carefully, remove any custom methods we have for exposing secrets during serialization
make sure we're using the pydantic attribute overridernutritious-balloon-65098
09/22/2025, 3:46 PMcalm-artist-7206
09/22/2025, 3:49 PMnutritious-balloon-65098
09/22/2025, 3:52 PMwhen_used="json" to when_used="always" in the field serializer to support both model_dump() and model_dump_json()
2. Removed custom method: Eliminated the model_dump_with_secrets() method that was creating special cases
3. Updated store_to_json: Changed to use model_dump(context={'expose_secrets': True}) instead of the custom method
Result
• Unified API: Both model_dump() and model_dump_json() now work with context={'expose_secrets': True}
• Standard Pydantic pattern: No more custom methods - uses built-in Pydantic context mechanism
• All tests pass: 730 SDK tests successful
• Clean implementation: Minimal, focused changes with no extraneous modifications
Usage
# Default behavior (masks secrets)
data = llm.model_dump()
# Expose secrets when needed
data = llm.model_dump(context={'expose_secrets': True})
json_data = llm.model_dump_json(context={'expose_secrets': True})
Pull Request Created: https://github.com/All-Hands-AI/agent-sdk/pull/423
The changes have been pushed to the cleanup-llm-serialization branch and a draft PR has been created. The implementation is ready and all tests are passing!
<sub>View full conversation</sub>calm-artist-7206
09/22/2025, 3:54 PMcalm-artist-7206
09/22/2025, 3:58 PMquick-window-91705
09/22/2025, 4:03 PMfile_store.write("my_location", agent.model_dump_json(context={'expose_secrets': True}))
to restore I call
agent_str = self.file_store.read("my_location")
agent = agent.model_validate_json(agent_str)straight-sundown-84319
09/22/2025, 4:19 PMstraight-sundown-84319
09/22/2025, 4:20 PMapi_key - at the moment this is sent as ****** - if we remove the SecretStr it would mean that the API now sends these keys, and we would need to make sure this is desired behaviorquick-window-91705
09/22/2025, 4:21 PMstraight-sundown-84319
09/22/2025, 4:22 PMwooden-umbrella-84098
09/22/2025, 4:31 PMchilly-france-44439
09/22/2025, 4:33 PM