2026-11-26 15:47 UTC

Squishling routes Ruby tasks between code and LLMs

state: watchingheat: lowuncertainty: lowrelevance: mediumtoken-optimization coding-agent rubyMichael CarrollCoolhand Labs

What is this?

Michael Carroll of Coolhand Labs released Squishling, an open-source Ruby gem that lets a class route work between deterministic Ruby code and an LLM. Calls share a strict output schema; routing can use predicates, missing implementations, or explicit fallback, and the project proposes comparing ongoing token costs with the cost of maintaining code. This is an application-level runtime pattern, not a tool for reducing tokens in coding agents themselves. The supplied evidence is the project’s GitHub documentation and two Hacker News launch posts; it does not establish adoption or independently verify performance or cost savings.

Why it matters

Squishling explores a useful architectural tradeoff: let an LLM handle a task until usage or maintenance economics justify writing deterministic code, while keeping a shared typed output contract. It could help Ruby teams prototype integrations, handle unusual inputs, or retire low-volume code paths. But this is not a coding-agent token-compression tool, and the supplied sources offer no independent evidence of adoption, reliability, or net savings.

Current assessment

Michael Carroll of Coolhand Labs introduced Squishling as an open-source Ruby gem for routing work between deterministic Ruby implementations and LLMs. Its documentation describes shared strict-schema-validated typed results, routing and fallback options, and frames code as a cache for AI judgment; schema validation does not establish factual correctness. The project makes a potentially useful application-level design pattern available, but it is not itself a coding-agent token-compression tool, and supplied sources do not independently establish reliability, adoption, or net cost savings. A later Hacker News item titles the project “Squishling 0.5.0 – hybrid LLM/Ruby code classes,” but provides no substantive release details; it does not yet change the assessment. Launch attention is low and steady well after its peak. Revisit if release details, independent evaluation, or production evidence clarifies where the approach is economical and reliable.

Measured heat

now 0 pts/hpeak 0 pts/hcomments 0/hpeers p10momentum: steady2 platformsage 1034h
points/hour across evidence · reading as of 2026-11-27 02:23:58.509736+11:00 · deterministic, not a model opinion

How the heat travelled

10-14 13:00⭐ origin echo-reconstructedSquishling: keep code only when it's cheaper than tokens; code as a cache for AI judgment.
Michael Carroll on github (echo) · attributed from hn.story.50105742
—
10-15 16:09first on hacker news · published · +27.2hShow HN: Squishling (Ruby gem) – Keep code only when it's cheaper than tokens
mikecarroll
—
10-15 16:09amplified on hacker news 👑hn.story.50105742
mikecarroll
peak 2 · 1 comments · 42% of case engagement
10-16 13:13amplified on hacker newshn.story.50117994
mikecarroll
peak 1 · 1 comments · 29% of case engagement
10-29 20:35amplified on hacker newshn.story.50295504
mikecarroll
peak 2 · 0 comments · 29% of case engagement
10-15 16:28our radar first saw it · +27.5hdiscovery anchor: hn.story.50105742—
pace: p40 vs 879 stories at the 720h mark (now 1034h old) — ahead of amex-ai-preparation-workforce-cuts (1.2x), behind ai-shopping-structured-product-data-advantage (0.9x)

Evidence (4) — ⭐ canonical anchor

sourceobjectauthorscorecomments
🟧 hnShow HN: Squishling (Ruby gem) – Keep code only when it's cheaper than tokens
Retrieved article excerpt

Open article · Retrieved 2026-10-15T16:35:26.482232+00:00

# [Squishling](https://github.com/Coolhand-Labs/squishling/blob/main/assets/squishling-logo.png)

**[📖 Read the Squishling explainer →](https://coolhand-labs.github.io/squishling/)**

[CI](https://github.com/Coolhand-Labs/squishling/actions/workflows/ci.yml)
[Gem Version](https://badge.fury.io/rb/squishling)

**Don't just use AI to write code. Use AI to not need code.** Write code only where it's worth maintaining.

A squished method either runs its Ruby implementation, with the LLM as a failover, or routes some callers
through an LLM as a way of eliminating (or discovering) the cost of maintaining them as deterministic code.
Either way it returns the same strict-schema-validated, typed result, so callers can't tell the difference.

Think of code as a cache for AI judgment. Every line you write is something to maintain, so the LLM is the
default and code has to earn its place: you build it for the inputs that carry the volume, and the LLM keeps
handling the rest. New to the idea? Read
[Elastic Software](https://everythingengineer.substack.com/p/beginners-write-software-with-ai) or browse the
[talk slides](https://michael.carroll.io/talks/2026/elastic-software/).

Or try it on the [explainer site](https://coolhand-labs.github.io/squishling/):

- [Spectrum slider](https://coolhand-labs.github.io/squishling/#spectrum): drag from traditional software to fully
  LLM and see the tradeoff at each point
- [Token-cost calculator](https://coolhand-labs.github.io/squishling/#number): price your tech debt in tokens
  against code upkeep
- [Walkthrough](https://coolhand-labs.github.io/squishling/#squishling): describe it, tune it, pay for accuracy,
  harden the common shapes

## Use cases

### Zero-code integrations

Accept a new data source today, before anyone writes a parser. Declare what you want back and leave the
method unimplemented: every call goes to the LLM, and its output is validated against your schema.

```
class ShipmentUpdate
  include Squishling

  purpose "Normalize this carrier's tracking webhook into our shipment update."
  output_schema do
    string :status, enum: %w[label_created in_transit out_for_delivery delivered exception]
    string :tracking_number
    string :location
  end
  # No `def call` yet, so every webhook goes to the LLM.
end

update = ShipmentUpdate.call(carrier: "acme-freight", payload: request.raw_post)
update.status        # => "out_for_delivery"
update.squished?     # => true
```

When one carrier carries the volume, write `def call` for it and add
`squish_when { |carrier:, **| carrier != "ups" }`. UPS then runs in Ruby, everything else stays on the
LLM, and callers don't change. See [Hardening a path](https://github.com/Coolhand-Labs/squishling/blob/main/docs/routing.md#hardening-a-path).

Validation guarantees the *shape* of the result, not that it's true. Where a wrong value is costly (money,
identity), cross-check it against another source or keep that path in Ruby.

### Rescue errors your code can't handle yet

Keep the Ruby you have for the inputs it understands, and hand the rest to the LLM instead of failing. When the
parser raises, `squish!` sends this call to the LLM with the error and the parser's own source as context.

```
class InvoiceParser
  include Squishling

  purpose "Extract the invoice fields from the vendor's document."
  append_to_purpose "The Ruby parser that handles well-formed invoices:", self   # this class's source
  output_schema do
    string :invoice_number
    number :total
  end

  def call(vendor:, document:)
    invoice = VendorFormats.fetch(vendor).parse(document)
    result(invoice_number: invoice.number, total: invoice.total)
  rescue VendorFormats::ParseError => e
    squish!(append_to_purpose: "The parser failed on this document; the error is in the context.",
            context: { parse_error: e })
  end
end

InvoiceParser.call(vendor: "acme", document: pdf_text).squished?    # => false (Ruby parsed it)
InvoiceParser.call(vendor: "acme", document: scanned_text).squished? # => true  (recovered by the LLM)
```

Both calls return the same result class. If the LLM can't deliver either, `squish_fallback` decides what to
return, or the error is raised with the original `ParseError` as its cause. See
[Handing off to the LLM](https://github.com/Coolhand-Labs/squishling/blob/main/docs/routing.md#handing-off-to-the-llm-with-squish).

### Retire code you no longer need

Go the other way too. Find the parsers and handlers that serve a thin tail of your traffic and squish them. When a
path's monthly token cost is lower than what its code costs to maintain, delete the code and relish the feeling of a
slimmer code base (or let your AI coding agent relish it).

### Measure your tech debt in tokens

Code you haven't written is debt you haven't taken on. A squished path has a running cost you can read off a
meter, so "should we write a parser for this?" becomes arithmetic: what the path costs in tokens each month,
against what it costs to write and maintain the code. Write it when the first number is bigger.

Add and initialize the [`coolhand`](https://github.com/Coolhand-Labs/coolhand-ruby) gem, and it picks up your
squishling calls automatically and measures their accuracy and cost:

```
# Gemfile
gem "coolhand"

# config/initializers/coolhand.rb
Coolhand.configure do |config|
  config.api_key = ENV.fetch("COOLHAND_API_KEY")
end
```

`squished?` tells you which path served a call. Coolhand records your LLM requests and responses; see
[what each tool sees](https://github.com/Coolhand-Labs/squishling/blob/main/docs/measuring-tokens.md#privacy). Want to roll your own metrics? Check out
[our guide](https://github.com/Coolhand-Labs/squishling/blob/main/docs/measuring-tokens.md) for doing it with other tools.

## Installation

```
gem "squishling"
```

Requires Ruby 3.3+ and RubyLLM 2.1+. Configure your provider API keys in RubyLLM as usual, then optionally set a
universal model, or an escalation of models to try in order:

```
Squishling.configure do |config|
  config.default_model = "claude-sonnet-5-5" # falls back to RubyLLM's default when nil
  # or: config.default_escalation = [{ model: "claude-haiku-4-5", attempts: 2 }, "claude-sonnet-5-5", "claude-opus-5-5"]
end
```

## How it works

A squishling class needs a **purpose** (the system prompt) and an **output schema** (the shape of the result,
validated on both paths). A squished call goes to the LLM when:

- its `squish_when` predicate is truthy for these inputs,
- the method has no implementation (it isn't defined, or raises `NotImplementedError`), or
- the Ruby implementation calls `squish!`.

Otherwise the Ruby runs, and whatever it returns is validated and typed like LLM output.

## Features

- **One contract, two paths**: Ruby returns and LLM output are validated against the same strict schema and
  returned as the same typed `Data` objects. `squished?` tells you which path served a call.
- **Your code as context**: `append_to_purpose` adds sections to the prompt, including a class's or method's
  own Ruby source.
- **Any RubyLLM provider and model**: OpenAI, Anthropic Claude, Google Gemini, AWS Bedrock, OpenRouter, and more.
  Set a universal, per-class, per-method, or per-call model, plus layered generation params (temperature,
  reasoning effort, top\_p, …).
- **Model escalation**: declare an `escalation:` instead of a `model:`, with per-step `attempts:`, `order:`, provider,
  params, and `forward_rejected:`. Invalid output (with its errors fed back) or a provider failure moves on to the next attempt. Steps can
  cross providers, e.g. a local Qwen model on Ollama, then Anthropic Claude Haiku on AWS Bedrock, then Claude Opus:

  ```
  RubyLLM.configure do |config|
    config.ollama_api_base = "http://localhost:11434/v1"
    config.bedrock_api_key = ENV["AWS_ACCESS_KEY_ID"]
    config.bedrock_secret_key = ENV["AWS_SECRET_ACCESS_KEY"]
    config.bedrock_region = "us-east-1"
    config.anthropic_api_key = ENV["ANTHROPIC_API_KEY"]
  end

  class TicketTriager
    include Squishling

    squishling escalation: [
      { model: "qwen3:8b", provider: :ollama, attempts: 2 },   # local and free, tried twice
      { model: "claude-haiku-4-5", provider: :bedrock },       # small hosted model
      { model: "claude-opus-5-5", provider: :anthropic }       # last resort
    ]
    # purpose, output_schema, ...
  end
  ```
- **[Harnesses](https://github.com/Coolhand-Labs/squishling/blob/main/docs/harnesses.md)**: choose how a call uses its escalation with `harness:`

  - [`:escalation`](https://github.com/Coolhand-Labs/squishling/blob/main/docs/configuration.md#models-and-escalation) (default): try each attempt until one passes
  - [`:squishsum`](https://github.com/Coolhand-Labs/squishling/blob/main/docs/harnesses.md#samples): two concurrent samples, accepted only if they agree
  - [`:judged_squishsum`](https://github.com/Coolhand-Labs/squishling/blob/main/docs/harnesses.md#the-judge): a chat or Jev judge picks between disagreeing samples
- **Output contracts**: beyond the strict schema, conditional rules (`given`) and Ruby checks (`squish_validate`)
  reject bad output and trigger the next attempt.
- **Defined failure behavior**: provider errors become `Squishling::LLMError`, and `squish_fallback` lets you decide
  what to return when every attempt fails.
- **Observability**: the opt-in [`squawk`](https://github.com/Coolhand-Labs/squishling/blob/main/docs/failures.md#observing-every-attempt-squawk) hook sends every attempt's
  raw output to your error tracker. Model output stays out of error messages and logs otherwise.
- **Opt-in context**: only method arguments, the instance state you name with `squish_context`, the `context:` you
  pass to `squish!`, and the source you choose to append are sent to the provider. The one addition: when
  [escalation](https://github.com/Coolhand-Labs/squishling/blob/main/docs/configuration.md#models-and-escalation) moves to the next step, that step also sees the previous
  model's rejected output, unless the step sets `forward_rejected: false`.

## Documentation

- [Explainer site](https://coolhand-labs.github.io/squishling/): interactive walkthrough, spectrum slider, and
  token-cost calculator
- [Configuration](https://github.com/Coolhand-Labs/squishling/blob/main/docs/configuration.md): options, models and escalation, providers, generation params, inheritance
- [Routing](https://github.com/Coolhand-Labs/squishling/blob/main/docs/routing.md): when a call goes to the LLM, `squish!`, `append_to_purpose`, hardening a path,
  what the LLM sees
- [Output schemas](https://github.com/Coolhand-Labs/squishling/blob/main/docs/schemas.md): schema forms, strict mode, typed results, optional vs. empty, contracts
- [Failure handling](https://github.com/Coolhand-Labs/squishling/blob/main/docs/failures.md): escalation, `squish_validate`, error classes, fallbacks
- [Harnesses](https://github.com/Coolhand-Labs/squishling/blob/main/docs/harnesses.md): escalation, squishsum, and judges (chat or Jev)
- [Naming and collisions](https://github.com/Coolhand-Labs/squishling/blob/main/docs/naming.md): the methods `include Squishling` adds and what happens when a name is taken
- [Measuring token spend](https://github.com/Coolhand-Labs/squishling/blob/main/docs/measuring-tokens.md): see what each squished path costs, with Coolhand Labs,
  the `squawk` hook, OpenTelemetry, LangSmith, or RubyLLM's instrumenter
- [Live examples](https://github.com/Coolhand-Labs/squishling/blob/main/examples/README.md): end-to-end tests against Anthropic Claude Haiku and OpenAI GPT-6 Luna

## Development

```
bin/setup
bundle exec rake        # RSpec (offline; RubyLLM is stubbed) + RuboCop
```

See [AGENTS.md](https://github.com/Coolhand-Labs/squishling/blob/main/AGENTS.md) for repo conventions, and [SECURITY.md](https://github.com/Coolhand-Labs/squishling/blob/main/SECURITY.md) for reporting vulnerabilities.
Have a suggestion to improve Squishling? [Open an issue](https://github.com/
mikecarroll21
🟧 echo.github ⭐Squishling: keep code only when it's cheaper than tokens; code as a cache for AI judgment.Michael Carroll——
🟧 hnRuby classes powered by LLM batteries (Squishling)mikecarroll11
🟧 hnSquishling 0.5.0 – hybrid LLM/Ruby code classesmikecarroll20

Interpretation history

Decision trace