← All articles

Practical guide · · By Raz Dagan

Define the input contract before replacing an LLM call with code

Specify missing values, Unicode, locale, numbers and unsupported inputs so a deterministic replacement preserves the behavior your application needs.

Write down what the function receives

A model may appear to accept almost anything because it interprets loosely formatted input. A deterministic replacement needs an explicit boundary: field types, required values, permitted formats and what happens when an input falls outside them. Start with the application payload, not a simplified example copied from a prompt.

For a customer-reference cleanup task, list whether the input is a string or object, whether whitespace has meaning, which character sets occur and whether leading zeros must be preserved. This contract is part of the behavior you evaluate; it should not be invented after a test mismatch.

Distinguish missing, empty and invalid values

Consider four cases separately: a missing property, null, an empty string and a string containing only spaces. Your application may treat them differently. A helper that converts all of them to an empty string can erase information even if most examples still pass.

Write an expected outcome for each case: accepted result, explicit rejection or fallback to the original path. Preserve the distinction through serialization and logging. Do not use a convenient default simply to keep the replacement from throwing an exception.

Make text normalization a deliberate policy

Visually identical text can have different Unicode representations. Case conversion can also depend on locale. The ECMAScript specifications describe normalization and locale-aware operations separately; choosing a text method is a behavior decision, not a universal cleanup step.

For example, a display name and a case-sensitive identifier should not automatically share a lowercasing rule. Define the permitted normalization form and locale when the task needs them, preserve the original value where appropriate, and include counterexamples that must remain distinct.

Keep numeric-looking identifiers separate from quantities

The reference 00127 can be an identifier rather than the number 127. Similarly, a decimal written with a comma may need a known locale before it can be parsed. Type coercion can silently change the meaning that the original workflow preserved.

Use an explicit schema and parsing policy. Define bounds, rounding, currency or units only when the task requires them. If a value cannot be interpreted reliably under the contract, return a bounded failure or route it to the supported fallback rather than guessing.

Build held-out cases around the boundary

Include normal examples and edge cases covering each contract rule. Keep some cases out of generation and development so the held-out evaluation can reveal a rule that only fits the examples used to build it.

A useful test table contains input, expected outcome, rule and reason. Add a pair of values that look similar but must differ, and a pair that should normalize to the same result. Score invalid-input behavior as well as successful output; a pass rate over easy inputs does not validate the contract.

Review the generated implementation in its actual runtime

Inspect implicit conversions, locale defaults and library behavior in the runtime where the customer's application will execute the code. A JavaScript implementation and a Python port need their own checks. ModelGate does not execute the Python port for you.

ModelGate can support the code-replacement and review workflow, but the customer application owns the deployed boundary and fallback behavior. Evaluate the generated replacement against held-out examples before rollout, then version the contract together with the code so later changes can be reviewed.

Primary references for the text boundary

The ECMAScript language specification documents String.prototype.normalize and text-processing behavior at https://tc39.es/ecma262/2025/multipage/text-processing.html. Consult it when choosing JavaScript normalization behavior rather than assuming all string methods normalize input.

The ECMAScript Internationalization API specification documents locale-sensitive case conversion at https://402.ecma-international.org/. These references define language operations; the correct business policy still depends on your application's identifiers and user inputs.

Explore the workflow

Read the code-replacement requirements, GitHub workflow and gateway comparison before deciding.