shipwithjev

Catalog / Tools & apps

0486GitHub

ruby_llm-typesafe

TypeSafe provider for RubyLLM 2.

kieranklaassen/ruby_llm-typesafeREADME ↗
# ruby_llm-typesafe

[](https://github.com/kieranklaassen/ruby_llm-typesafe/actions/workflows/ci.yml)
[](https://rubygems.org/gems/ruby_llm-typesafe)

A [RubyLLM](https://rubyllm.com) 2 provider for [TypeSafe](https://typesafe.ai).

TypeSafe runs Jev, a System One model. Jev does not write text. You give it one piece of state (a string, or JSON your application already has) and a batch of typed questions. It answers each question with a probability your code can act on. There are three question types, which TypeSafe calls primitives:

- Noul asks whether something is true and returns the probability of yes.
- Choice picks one option from a set you define and returns a probability for each option.
- Score rates the state against ordered levels you define and returns a weighted position on that scale.

This gem adds a `:typesafe` provider to RubyLLM. Because TypeSafe only returns typed answers, the provider works through RubyLLM's structured output API and nothing else. You build the questions with `RubyLLM::Providers::TypeSafe::Schema`, pass them to `chat.with_schema`, call `ask` with the state, and read the answers from `response.parsed`. Calling `ask` without a schema, streaming, and tools raise an error before any request is sent (see [Structured output only](#structured-output-only)).

```ruby
require 'ruby_llm-typesafe'

RubyLLM.configure do |config|
  config.typesafe_api_key = ENV['TYPESAFE_API_KEY']
end

schema = RubyLLM::Providers::TypeSafe::Schema.new do |s|
  s.noul :is_urgent, instructions: 'Does this convey urgency?'
  s.choice :department, instructions: 'Which team should handle this?',
                        criteria: { billing: 'Payments, invoicing, refunds',
                                    technical: 'Bugs, outages, integrations',
                   

Also filed under Tools & apps