AivexaNewsSearch
AI news for builders and product teamsChecked every hour

Cut generative AI costs: Code for rules, models for judgment

Collected Nov 17, 2026

AWS published guidance on its Machine Learning Blog arguing that the largest cost decision in a generative AI system is whether a model gets called at all. The post lays out a three-question test for each step in a workflow, maps every outcome to a specific AWS service, and closes with a four-step adoption plan. It is aimed at teams whose prototypes have quietly grown into production pipelines where validation, reformatting and routing all pass through an LLM.

The pattern the post describes starts in the prototype: because a model call worked for one step, it became the default for the next. At prototype volume nobody notices; at production volume the practice bites in three ways. Spend grows with request count even for low-value steps, latency compounds because each call in a chain adds hundreds of milliseconds, and outputs vary for identical inputs, which complicates testing and slows audits. Each new model launch then restarts the internal debate about which model to use, while the more basic question goes unasked.

The decision procedure is deliberately short. First: can a rule check success, such as a format, schema, keyword or numeric range? If a rule settles part of the step, it runs as a fast path and only the remainder moves on. Second: can a model write the rule once, such as a regular expression or JSON schema, which is then reviewed and committed to code? Third: does the step pick one answer from a fixed list of routes, classes or yes/no outcomes? If all three answers are no, the step is open-ended and belongs on a right-sized model.

A customer support assistant illustrates the split. Order number format checks become an Amazon API Gateway REST API request validator or a Lambda function. Intent routing starts with a keyword match on terms like "refund," implemented as an AWS Step Functions Choice state using JSONata, with the residual passed to a constrained decision call. Extracting a tracking number from a carrier email is handled by having a model draft a regular expression once, which a human reviews and commits as a Lambda pattern. Choosing one of four queues is a constrained decision call that escalates when unsure. Drafting the customer reply is the one step that runs on the smallest Bedrock model meeting the requirements.

The post contrasts the two extremes directly. Deterministic code costs orders of magnitude less per invocation, runs in single-digit milliseconds or less, is exact for the rule as written, sits in source control for auditors, and stays stable until someone changes it. A model call is billed per token, adds hundreds of milliseconds, carries a non-zero error rate even on well-specified rules, is harder to explain to an auditor, and can shift behavior when a model version changes or is retired. A temperature of 0 makes varied answers less likely but does not guarantee identical output, and models can hallucinate. Bedrock model evaluation and Bedrock Guardrails are named as tools for measuring and containing those risks. The post offers a practical heuristic: if the acceptance test can be written as a rule, the step can usually be written as a rule.

Routing and classification sit in between, and the post argues they should decide rather than generate. Four AWS-compatible ways to build such a call are given. A small Bedrock model with structured outputs constrained to an enum plus an "unsure" option is the simplest, though its confidence is the model's own judgment rather than a calibrated score and needs checking against labeled data. Embedding similarity against labeled examples uses the nearest-neighbor score as the escalation signal, with the threshold set on labeled data. Strands Decider, an experimental open-source decision model under the Apache License 2.0, returns a calibrated confidence per answer; its README reports that answers at 0.9 confidence or above are correct about 95 percent of the time on short classification tasks, a figure the post says should be re-validated before production use. A trained classifier on Amazon SageMaker AI returns class probabilities at low latency and cost once labeled training data exists.

The post includes a JSON schema restricting a structured-output answer to billing, technical, account, other or unsure, noting that Bedrock requires `additionalProperties: false` on every schema object. It also stresses that authorization decisions, such as a refund limit, belong in a rule rather than a model.

The deterministic fast path gets its own section. A Step Functions Choice state can branch before any model is invoked, Lambda hosts rules needing more than a choice, and API Gateway request validation rejects malformed input before compute runs. With illustrative, explicitly non-benchmark arithmetic, the post notes that if rules resolve 95 percent of requests, only one in twenty reaches a model, before any savings from model selection. A sample Choice state uses JSONata `$contains` conditions to send refund and password-reset messages straight to code and everything else to the constrained decision call.

Having a model draft a regular expression once instead of running a model every time is offered as a middle path, with a caution to test model-written patterns against known good and bad inputs and to avoid nested quantifiers such as `(a+)+`, which can cause catastrophic backtracking, or ReDoS. For generative steps, Bedrock structured outputs constrain responses to a developer-defined JSON schema so code can parse them without custom logic, though the post reminds readers to check content for correctness and to keep range checks in code. Rules stored in configuration should be limited to known primitives such as regexes, schema checks, keyword lists and range checks; arbitrary code should never be executed from a config file.

When a model is genuinely needed, the post recommends right-sizing: choosing the cheapest and fastest model that clears the quality floor, which is often not the newest or largest. Requirements should be defined before comparison: a quality floor measured on a golden evaluation set of labeled examples, a cost ceiling per request or per successful outcome, a p95 or p99 latency target, and compliance constraints such as data residency. Bedrock's multi-family API allows per-task right-sizing without changing integration code, while Intelligent Prompt Routing selects among models within a family and Model Distillation transfers knowledge from a larger model to a smaller one.

Model choice should itself be a tested configuration. The post recommends a golden evaluation set per task run in continuous integration, gating on requirements so a cheaper model that drops below the quality floor counts as a regression, putting the model behind a configuration flag for easy rollback, matching the oracle to the task (ground truth for rules, model-as-judge only for open-ended output), and sampling rule-resolved requests through a model in shadow mode to detect drift. The rollout plan is to instrument every call by category and track cost per successful outcome, move rule-checkable steps to Lambda or Step Functions as the largest and safest win, add constrained decision calls for fixed-choice steps, and evaluate each new model against the golden set before it becomes the default.

Why it matters: Teams running LLM pipelines at volume stand to cut both spend and latency by moving format checks, validation and routing into code, and the escalation pattern gives product teams a way to keep model judgment only where ambiguity is real. The trade-off is added architectural complexity and a new evaluation discipline: golden sets, confidence thresholds and drift monitoring all become ongoing work rather than one-time setup. For developers, the practical implication is that prompt and model selection should be treated as configuration under test, not as a design decision made once.

Read at AWS Machine Learning Blog

Based on reporting from the original publisher. Visit the source for full context and later updates.

Publisher excerpt

The biggest cost lever in a generative AI system is whether you call a model at all. Learn how to decide whether each workflow step needs a model, and map each option to AWS: deterministic code, a constrained decision call, or a right-sized model on Amazon Bedrock.