Skip to content

Fix chat response job template to use String#empty? instead of #blank? when streaming#537

Closed
kryzhovnik wants to merge 1 commit into
crmne:mainfrom
kryzhovnik:main
Closed

Fix chat response job template to use String#empty? instead of #blank? when streaming#537
kryzhovnik wants to merge 1 commit into
crmne:mainfrom
kryzhovnik:main

Conversation

@kryzhovnik

@kryzhovnik kryzhovnik commented Dec 12, 2025

Copy link
Copy Markdown
Contributor

What this does

Use empty? instead of blank? so whitespace-only chunks (e.g., "\n" or " ") aren’t dropped

Why

"\n".blank?  # => true
"\n".empty?  # => false
"".empty?    # => true

For example, LLM output is often whitespace-sensitive (think Markdown): dropping streamed newlines or spaces can change the rendered result, even if HTML would ignore them

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • Performance improvement

Scope check

  • I read the Contributing Guide
  • This aligns with RubyLLM's focus on LLM communication
  • This isn't application-specific logic that belongs in user code
  • This benefits most users, not just my specific use case

Quality check

  • I ran overcommit --install and all hooks pass
  • I tested my changes thoroughly
    • For provider changes: Re-recorded VCR cassettes with bundle exec rake vcr:record[provider_name]
    • All tests pass: bundle exec rspec
  • I updated documentation if needed
  • I didn't modify auto-generated files manually (models.json, aliases.json)

API changes

  • Breaking change
  • New public methods/classes
  • Changed method signatures
  • No API changes

String#blank? returns true for whitespace-only chunks (including newlines), so it can drop streamed content:

```ruby
"\n".blank? # => true
```

String#empty? only rejects zero-length strings:

```ruby
"\n".empty? #=> false
"".empty? #=> true
```

LLM output is often Markdown; newlines and spaces affect rendering (unlike HTML where whitespace is often collapsed without impact) so we should keep whitespace chunks during streaming
@kryzhovnik

Copy link
Copy Markdown
Contributor Author

Replaced by #636 — opened from a feature branch with a cleaner diff and improved description.

@kryzhovnik kryzhovnik closed this Feb 26, 2026
crmne pushed a commit that referenced this pull request Feb 26, 2026
## Summary

`String#blank?` drops whitespace-only chunks (newlines, spaces) during
streaming. LLM output can include content where whitespace is
significant for correct rendering (e.g. Markdown), so use
`String#empty?` instead to only skip truly empty chunks.

Replaces #537 (was opened from main by mistake).
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