Skip to content

Handle tool hallucination gracefully#580

Merged
crmne merged 1 commit intocrmne:mainfrom
altertable-ai:su/tool-hallucination
Mar 1, 2026
Merged

Handle tool hallucination gracefully#580
crmne merged 1 commit intocrmne:mainfrom
altertable-ai:su/tool-hallucination

Conversation

@redox
Copy link
Contributor

@redox redox commented Jan 23, 2026

What this does

While asking what tools do you support? I managed to have the underlying LLM hallucinate it could call a tool list_tools which ended up failing with a NPE (nil.call(args)) because I didn't have such tool available...

This is an attempt at dealing with this hallucination in a nicer way, inspired by what others are doing (eg. Vercel
AI
).

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

At a question `what tools do you support`, I managed to have the LLM
hallucinate it could call a tool `list_tools` which ended up failing
with a NPE.

This is an attempt at dealing with this in a nicer way, inspired by what
others are doing (eg. [Vercel
AI](https://github.com/vercel/ai/blob/52fc8fb2b9e797550e8e1ce7bde3afdf9e47f35c/packages/ai/src/error/no-such-tool-error.ts#L16)).
@crmne crmne merged commit 0443bf7 into crmne:main Mar 1, 2026
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