Skip to content

Avoid a TypeError in isTextSafe when the model returns no output#73317

Open
cnbrenci wants to merge 1 commit into
stagingfrom
cassi/aichat/istextsafe-optional-output
Open

Avoid a TypeError in isTextSafe when the model returns no output#73317
cnbrenci wants to merge 1 commit into
stagingfrom
cassi/aichat/istextsafe-optional-output

Conversation

@cnbrenci

Copy link
Copy Markdown
Contributor

What

isTextSafe read response.output.classification directly. When the AI gateway returns no structured output (response.output is undefined), that throws a raw TypeError ("Cannot read properties of undefined") instead of the intended error.

Use optional chaining (response.output?.classification) so an undefined output falls through to the existing guard, which throws a clear Invalid classification value: undefined.

Testing

One-line defensive change; no behavior change when output is present. Covered by the existing safety-helpers path; drone runs the unit suite.

🤖 Generated with Claude Code

isTextSafe read response.output.classification directly, which throws a raw
TypeError when the gateway returns no structured output. Use optional chaining
so classification falls through to the existing "Invalid classification value"
guard instead.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

1 participant