You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Enable Langchain::Tool::RubyCodeInterpreter on Ruby 3.3+ (#977)
safe_ruby has supported Ruby 3.3+ since version 1.0.5:
ukutaht/safe_ruby#4 (comment)
## Before (using safe_ruby 1.0.4)
A `NameError` occurred when running under Ruby 3.3:
```console
$ ruby -v
ruby 3.3.8 (2025-04-09 revision b200bad6cd) [x86_64-darwin24]
$ bundle exec ruby -rlangchain -e "Langchain::Tool::RubyCodeInterpreter.new.execute(input: '[1, 2, 3].map{ |n| n + 1 }')"
D, [2025-05-01T00:15:18.396619 #61580] DEBUG -- [Langchain.rb]: Langchain::Tool::RubyCodeInterpreter - Executing "[1, 2, 3].map{ |n| n + 1 }"
/Users/koic/.rbenv/versions/3.3.8/lib/ruby/gems/3.3.0/gems/safe_ruby-1.0.4/lib/safe_ruby/runner.rb:45:
in `rescue in eval': /var/folders/6j/5l8q3y250b97529_tcssrwlm0000gn/T/saferuby20250430-90315-4c2rkb:17:
in `undef_method': undefined method `new' for class `String' (NameError) (RuntimeError)
klass.send(:undef_method, method)
^^^^^
Did you mean? next
from /var/folders/6j/5l8q3y250b97529_tcssrwlm0000gn/T/saferuby20250430-90315-4c2rkb:17:in `block in keep_methods'
from /var/folders/6j/5l8q3y250b97529_tcssrwlm0000gn/T/saferuby20250430-90315-4c2rkb:16:in `each'
from /var/folders/6j/5l8q3y250b97529_tcssrwlm0000gn/T/saferuby20250430-90315-4c2rkb:16:in `keep_methods'
from /var/folders/6j/5l8q3y250b97529_tcssrwlm0000gn/T/saferuby20250430-90315-4c2rkb:37:in `<main>'
from /Users/koic/.rbenv/versions/3.3.8/lib/ruby/gems/3.3.0/gems/safe_ruby-1.0.4/lib/safe_ruby/runner.rb:41:in `eval'
from /Users/koic/.rbenv/versions/3.3.8/lib/ruby/gems/3.3.0/gems/safe_ruby-1.0.4/lib/safe_ruby/runner.rb:20:in `eval'
from /Users/koic/src/github.com/patterns-ai-core/langchainrb/lib/langchain/tool/ruby_code_interpreter.rb:38:in `safe_eval'
from /Users/koic/src/github.com/patterns-ai-core/langchainrb/lib/langchain/tool/ruby_code_interpreter.rb:34:in `execute'
from -e:1:in `<main>'
<internal:marshal>:34:in `load': incompatible marshal file format (can't be read) (TypeError)
format version 4.8 required; 47.118 given
from /Users/koic/.rbenv/versions/3.3.8/lib/ruby/gems/3.3.0/gems/safe_ruby-1.0.4/lib/safe_ruby/runner.rb:42:in `eval'
from /Users/koic/.rbenv/versions/3.3.8/lib/ruby/gems/3.3.0/gems/safe_ruby-1.0.4/lib/safe_ruby/runner.rb:20:in `eval'
from /Users/koic/src/github.com/patterns-ai-core/langchainrb/lib/langchain/tool/ruby_code_interpreter.rb:38:in `safe_eval'
from /Users/koic/src/github.com/patterns-ai-core/langchainrb/lib/langchain/tool/ruby_code_interpreter.rb:34:in `execute'
from -e:1:in `<main>'
```
## After (using safe_ruby 1.0.5)
No error occurs:
```console
$ ruby -v
ruby 3.3.8 (2025-04-09 revision b200bad6cd) [x86_64-darwin24]
$ bundle exec ruby -rlangchain -e "Langchain::Tool::RubyCodeInterpreter.new.execute(input: '[1, 2, 3].map{ |n| n + 1 }')"
D, [2025-05-01T00:16:09.404532 #63102] DEBUG -- [Langchain.rb]: Langchain::Tool::RubyCodeInterpreter - Executing "[1, 2, 3].map{ |n| n + 1 }"
```
Ruby 3.4 works as well.
# Langchain.rb a is library for building LLM-backed Ruby applications. It is an abstraction layer that sits on top of the emerging AI-related tools that makes it easy for developers to consume and string those services together.
0 commit comments