Skip to content

Add RubyLLM::Contract to Ecosystem#808

Merged
crmne merged 2 commits into
crmne:mainfrom
justi:add-ruby-llm-contract-ecosystem
Jun 13, 2026
Merged

Add RubyLLM::Contract to Ecosystem#808
crmne merged 2 commits into
crmne:mainfrom
justi:add-ruby-llm-contract-ecosystem

Conversation

@justi

@justi justi commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

What this does

This adds the gem RubyLLM::Contract to the Ecosystem documentation. It is a Ruby library that wraps RubyLLM::Chat with input/output contracts, business-rule validation, retry with model escalation on validation failure, pre-flight cost ceilings, and a regression-eval framework. It catches schema-valid-but-logically-wrong output at the boundary of your system before it ships to production.

Example Usage

class SummarizeArticle < RubyLLM::Contract::Step::Base
  prompt <<~PROMPT
    Summarize this article for a UI card. Return a short TL;DR,
    3 to 5 key takeaways, and a tone label.

    {input}
  PROMPT

  output_schema do
    string :tldr
    array  :takeaways, of: :string, min_items: 3, max_items: 5
    string :tone, enum: %w[neutral positive negative analytical]
  end

  validate("TL;DR fits the card")  { |o, _| o[:tldr].length <= 200 }
  validate("takeaways are unique") { |o, _| o[:takeaways] == o[:takeaways].uniq }

  retry_policy models: %w[gpt-4.1-nano gpt-4.1-mini gpt-4.1]
end

result = SummarizeArticle.run(article_text)
result.parsed_output  # => { tldr: "...", takeaways: [...], tone: "analytical" }

The gem is complementary to RubyLLM::Tribunal - Contract gates at runtime (before output reaches your code, with retries on failure), Tribunal grades at test-time (after output is in your code, in a spec).

Type of change

  • Documentation

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

API changes

  • No API changes

🤖 Generated with Claude Code

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@codecov

codecov Bot commented Jun 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.10%. Comparing base (f82711f) to head (af2eb09).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #808   +/-   ##
=======================================
  Coverage   82.10%   82.10%           
=======================================
  Files         137      137           
  Lines        6344     6344           
  Branches     1122     1122           
=======================================
  Hits         5209     5209           
  Misses        684      684           
  Partials      451      451           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@crmne crmne merged commit 625fb38 into crmne:main Jun 13, 2026
21 checks passed
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