Skip to content

hunch (carldaws)

Ruby gem for probabilistic control flow: branch on Jev answers with predicates like likely? and almost_certainly?.

LibrarybetaMIT

Overview

Hunch is a Ruby library, with a TypeScript port, that turns judgment calls into ordinary control flow. You write a question in plain English and pass application data with given:, and Hunch asks a System One model such as Jev for a calibrated probability. chance returns a number; graded predicates such as possibly?, likely?, probably? and almost_certainly? compare it to configurable thresholds (0.25, 0.5, 0.75, 0.93 by default); pick chooses one of several options; and rate returns a level on an ordered scale with a position you can compare.

Hunch.decide batches several questions about the same data into one API call. It is aimed at Ruby and Rails developers, and the README shows uses in ActiveRecord validations, mail routing and fraud holds, with an example Rails app and tests. The backend is pluggable; the documented configuration reaches Jev through OpenRouter, and there is support for test backends so app tests do not hit the API.

What the decision model decides

TypeQuestionAnswers
Yes / nothis order is fraudulentyes · no
ChoiceWhich team: billing, technical or sales?billing · technical · sales
ScoreWhat is the mood of this email?calm · frustrated · livid

How it works

  1. Configure a System One backend (e.g. Jev via OpenRouter)
  2. Call chance, a predicate, pick or rate with given: data
  3. Hunch sends the question and returns a probability or Ruby value
  4. Branch with ordinary if/else or validations; batch with Hunch.decide

Strengths

  • Reads like plain Ruby while branching on calibrated probabilities
  • Named thresholds make risk tolerance explicit and configurable
  • Batching asks many questions in one call
  • Pluggable backends allow offline testing

Caveats

  • Each predicate call is a network request with cost and latency
  • Thresholds are defaults and need tuning per use case

Getting started

Add `gem "hunch"` and configure `Hunch::Backends::SystemOne.new(url: "https://openrouter.ai/api/alpha/decisions", api_key: ENV["OPENROUTER_API_KEY"], model: "typesafe/jev-1.13")`.

At a glance

Type
Library
Status
beta
Language
Ruby
Runtime
library (Rails-friendly)
Has code
yes
Has tests
yes
License
MIT

Use cases and integrations

How curated lists describe it

  • Ruby ecosystem: turns judgment calls into control flow — `if Hunch.likely?("fraudulent", given: order)` reads like plain Ruby but branches on a typed Jev answer, with `pick` for Choice, `rate` for Score, and graded predicates from `possibly?` to `almost_certainly?`; a [TypeScript port](https://github.com/carldaws/hunch-ts) offers the same interface.

    yibie/awesome-jev
  • Probabilistic control flow for Ruby: `if Hunch.likely?("fraudulent", given: order)` branches on a typed Jev answer, with graded predicates from `possibly?` to `almost_certainly?`; a [TypeScript port](https://github.com/carldaws/hunch-ts) offers the same interface.

    cobanov/awesome-jev
  • Probabilistic control flow for Ruby and Rails, with predicates that read like ordinary conditionals.

    MrJev/awesome-jev

Frequently asked questions

What does Hunch decide?

Whatever you ask: yes/no probabilities, a choice between options, or a level on a scale, returned as Ruby values.

How do I reach Jev?

The README configures the System One backend against OpenRouter's decisions endpoint with model typesafe/jev-1.13.

Is there a JavaScript version?

Yes, @carldaws/hunch offers the same interface in TypeScript.

Related projects

  • Ax, a DSPy-style multi-language LLM framework, listed with a native TypeSafe provider for Boolean, Choice, Score and raw Jev questions.

    PluginproductionTypeScript
  • Effect TypeScript library whose @effect/ai-typesafe package maps classify, probability and rating operations to Jev questions.

    ProjectproductionTypeScript
  • PHP monorepo whose Polyglot module adds a TypeSafe driver for typed Noul, Choice and Score decisions alongside LLM inference.

    ProjectproductionPHP
  • Elixir library for unified LLM calls across providers, with an evaluate interface that calls Jev via TypeSafe or OpenRouter.

    ProjectproductionElixir
  • Self-hosted multi-tenant AI agent platform listed as including optional TypeSafe client tools for classification, scoring and yes/no.

    LibraryproductionPython
  • Provider-agnostic TypeScript AI SDK; per list sources, an @tanstack/ai-typesafe adapter exposes Jev decisions through decide().

    ServiceproductionTypeScript