Skip to content

fix responses.create to accept plain string input#46

Merged
kdr merged 1 commit intomainfrom
kdr-fix-bug
Feb 11, 2026
Merged

fix responses.create to accept plain string input#46
kdr merged 1 commit intomainfrom
kdr-fix-bug

Conversation

@kdr
Copy link
Contributor

@kdr kdr commented Feb 11, 2026

Summary

  • Fixed client.responses.create(input="some string", ...) failing because the generated Pydantic CreateResponseRequestInput oneOf model can't be auto-coerced from a raw string
  • Added _normalize_input() helper in the client resource layer that properly wraps input into the generated model types
  • Supports plain strings, simple message dicts ([{"role": "user", "content": "text"}]), and fully-structured API format
  • Bumped version to 0.6.1

Test plan

  • Verified string input serializes correctly: input="What does amy talk about"
  • Verified simple dict input serializes correctly: input=[{"role": "user", "content": "text"}]
  • Verified fully-structured input serializes correctly
  • End-to-end test with live API

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Enhanced input handling for response creation, now accepting flexible formats including plain text or structured message lists.
  • Chores

    • Version updated to 0.6.1.

The SDK's CreateResponseRequestInput oneOf model couldn't be
auto-coerced from a raw string by Pydantic. Added _normalize_input()
to properly wrap string and simple dict inputs into the generated
model types.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link

coderabbitai bot commented Feb 11, 2026

📝 Walkthrough

Walkthrough

A new private helper function _normalize_input() converts flexible user input (strings or lists of dicts) into typed CreateResponseRequestInput for the responses resource, replacing direct input assignment in the create() method. Version bumped to 0.6.1.

Changes

Cohort / File(s) Summary
Input Normalization
cloudglue/client/resources/responses.py
Added _normalize_input() private helper function to convert flexible user input formats (string or list of dicts) into typed CreateResponseRequestInput. Updated create() method to use normalization. Added imports for CreateResponseRequestInput, ResponseInputContent, and ResponseInputMessage.
Version Update
pyproject.toml
Bumped project version from 0.6.0 to 0.6.1.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A helper hops in, so nimble and bright,
Converting wild inputs to structures so right,
From strings and from dicts, a tale of great care,
The version climbs up through the cleaner air! 🌟

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding support for plain string input to responses.create() method.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch kdr-fix-bug

No actionable comments were generated in the recent review. 🎉

🧹 Recent nitpick comments
cloudglue/client/resources/responses.py (1)

28-43: Unguarded dict key access will surface as raw KeyError instead of a helpful message.

msg["role"] (Line 41) and c["text"] (Line 35) will raise bare KeyError if the caller omits those keys. Since this is a user-facing convenience layer, a friendlier error (or a ValueError with a message) would improve DX.

Also, msg.get("content") (Line 30) can return None if the key is absent. That None would be passed straight through to ResponseInputMessage(content=None), which may or may not be valid depending on the generated model's schema.

Proposed improvement
     for msg in input:
+        if "role" not in msg:
+            raise ValueError("Each message dict must include a 'role' key")
         content = msg.get("content")
         if isinstance(content, str):
             content = [ResponseInputContent(type="input_text", text=content)]
         elif isinstance(content, list):
             content = [
-                ResponseInputContent(type=c.get("type", "input_text"), text=c["text"])
+                ResponseInputContent(type=c.get("type", "input_text"), text=c.get("text", ""))
                 if isinstance(c, dict) else c
                 for c in content
             ]
+        elif content is None:
+            raise ValueError("Each message dict must include a 'content' key")

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@kdr kdr requested a review from amyxst February 11, 2026 20:25
@kdr kdr merged commit 3ef6878 into main Feb 11, 2026
1 check passed
@kdr kdr deleted the kdr-fix-bug branch February 11, 2026 20:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants