← all repositories
patterns-ai-core/langchainrb

Swap LLM providers without rewriting your Ruby app

A Ruby toolkit that normalizes embeddings, chat completions, and prompt templates across eleven LLM backends so you don't have to write provider-specific glue.

langchainrb
Not currently ranked — collecting fresh signals.
star history

What it does Langchain.rb is a Ruby gem for adding LLM features—embeddings, chat completions, and structured output parsing—to Ruby applications. It wraps providers like OpenAI, Anthropic, Google Gemini, and Ollama behind a single Langchain::LLM interface, letting you change backends by swapping the instantiated class. The toolkit also includes prompt templates with few-shot support, JSON schema enforcement, and an auto-repairing output parser that asks the model to fix its own malformed JSON.

The interesting bit The library normalizes response objects across all providers, so embeddings, completions, token counts, and tool calls arrive in the same shape regardless of backend. The OutputFixingParser is a nice recursive touch: when structured JSON parsing fails, it automatically sends the error and original output back to the LLM for correction.

Key highlights

  • Eleven supported providers, from commercial APIs to local Ollama instances.
  • Prompt templates with variable substitution, few-shot examples, and JSON/YAML serialization.
  • StructuredOutputParser enforces JSON schema compliance; OutputFixingParser auto-heals broken responses.
  • Normalized response objects for embeddings, chat completions, tool calls, and token usage.
  • Dependencies are modular: only the provider gems you need are required.

Caveats

  • Google Gemini and Google VertexAI use a different message format than the standard tuple structure, so portability has limits.
  • Provider-specific features and parameters are not fully abstracted; the README advises checking per-class docs for extra options.
  • You must manually install additional provider gems; nothing is bundled by default.

Verdict Ruby developers building RAG systems or chat assistants who want to avoid Python ecosystem lock-in will find a sensible adapter layer here; those already committed to Python’s LangChain ecosystem have little incentive to migrate.

Frequently asked

What is patterns-ai-core/langchainrb?
A Ruby toolkit that normalizes embeddings, chat completions, and prompt templates across eleven LLM backends so you don't have to write provider-specific glue.
Is langchainrb open source?
Yes — patterns-ai-core/langchainrb is open source, released under the MIT license.
What language is langchainrb written in?
patterns-ai-core/langchainrb is primarily written in Ruby.
How popular is langchainrb?
patterns-ai-core/langchainrb has 2k stars on GitHub.
Where can I find langchainrb?
patterns-ai-core/langchainrb is on GitHub at https://github.com/patterns-ai-core/langchainrb.

heatdrop uses Google Analytics to see which pages get read — nothing else. Your call. How we handle data.