{"repo":"justi/ruby_llm-contract","free":true,"listed":false,"github":"https://github.com/justi/ruby_llm-contract","clone":"git clone https://github.com/justi/ruby_llm-contract.git","description":"Validate and retry LLM outputs for ruby_llm. Describe the JSON response you expect, fall back to a stronger model when the cheaper one fails the rules, and gate CI on regressions — all as one contract object per step.","language":"Ruby","stars":35,"topics":["ai","anthropic","cost-tracking","eval","llm","model-comparison","openai","rails","regression-testing","ruby"],"license":"MIT","category":"ai-agents","readme_excerpt":"ruby llm-contract Contracts + Evals for ruby llm. Your eval passed. Prod broke anyway? This gem 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 — so a flaky cheap-model call escalates to a stronger model instead of shipping garbage to your user. ruby llm handles the HTTP side (rate limits, timeouts, streaming, tool calls, embeddings). This gem handles what the model returned at runtime : schema validation, business rules, model escalation on failed validation, regression datasets that gate prompt/model changes in CI. Install Works with any ruby llm provider (OpenAI, Anthropic, Gemini, etc). Requires ruby llm 1.12 and Ruby ≥ 3.2. Example A Rails app takes article text extracted from a user-submitted URL and wants to show a summary card: a short TL;DR, 3–5 key takeaways, and a tone label. The output has to fit the UI (TL;DR under 200 chars) and the schema has to be strict enough to render without conditionals. Three things to notice in the snippet above: - {input} is a gem-specific prompt placeholder — at call time SummarizeArticle.run(article text) interpolates article text into that slot. For input type Hash , each top-level key becomes its own placeholder (e.g. {title} , {body} ). Plain text in, plain text out — no ERB, no String#% . - validate(\"...\") { o, ... } — each block receives (parsed output, context) ; the convention o, reads \"output","default_branch":null,"files":null,"tree":[],"storefront":"/r/justi","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/justi/ruby_llm-contract/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}