Skip to content

Conversation

@kryzhovnik
Copy link

@kryzhovnik kryzhovnik commented Dec 12, 2025

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
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