Topic 2 of 5 · 4 min read
Feature flags for model, prompt and tool access
Goal: Define flags that let a team expose a feature, swap its model and disable one risky tool independently.
Give every part of an LLM feature that can change or fail its own flag, so you can expose the feature, swap its model and turn off one tool without touching the others. One flag called ai_assistant is not enough.
Check yourself · 1 of 3
Why give a risky tool its own flag instead of using the feature's flag?
Why it matters
An LLM feature has at least four moving parts: whether it shows at all, which model answers, which prompt version is used, and which tools the model may call. Providers retire models, a prompt edit can drop quality, and one tool can turn out to be risky. If all of that sits behind one switch, the only response to any problem is to turn off everything.
How to do it
- Separate the flags. A release flag for the feature, a config flag for the model name, a config flag for the prompt version, and one permission flag per risky tool.
- Target by context. Evaluate each flag with the user, tenant and plan. Staff first, then a tenant list, then a percentage, then everyone.
- Fail safe. If the flag service is unreachable, use a default that is off for risky tools and the last known value for the model.
- Log the values. Put the flag values on every trace and eval record, or you cannot explain why quality moved.
- Remove stale flags. Each flag gets an owner and a removal date. A fully launched release flag is deleted from code, not left behind.
Before and after
Weak:
if (flags.isOn("ai_assistant")) {
return runAgent({ model: "big-model-v2", prompt: PROMPT, tools: ALL_TOOLS });
}
Better:
const ctx = { userId, tenantId, plan };
if (!(await flags.bool("assistant.enabled", false, ctx))) return null;
return runAgent({
model: await flags.string("assistant.model", "model-a", ctx),
prompt: await flags.string("assistant.prompt_version", "v7", ctx),
tools: [
searchDocs,
...((await flags.bool("assistant.tool.send_email", false, ctx)) ? [sendEmail] : []),
],
});
A provider-neutral API such as OpenFeature keeps this code the same if you change flag vendors.
What goes wrong
- One flag for everything. You cannot disable the email tool without losing search.
- Defaults that fail open. The flag service times out and every user gets the risky tool.
- Flag debt. Dozens of old flags interact, and nobody knows which combinations were ever tested.
Examples
Disabling one tool during an incident
Users report that the assistant sometimes creates duplicate calendar events. The team sets assistant.tool.create_event to false for all tenants. Search and drafting keep working, and the fix ships on its own schedule. With a single feature flag, the whole assistant would have gone offline.
Swapping the model for one tenant
A provider announces a model retirement. The team sets assistant.model to the replacement for the internal tenant only, compares eval scores logged with the flag value for a week, then widens to a 10% cohort. A pinned model name in code would have needed a deploy for each step.
Key points
- Use separate flags for the feature, the model, the prompt version and each risky tool.
- Evaluate flags with user, tenant and plan context to roll out in stages.
- Defaults must fail safe: risky tools off when the flag service is down.
- Record flag values on every trace and eval so quality changes can be explained.
- Give each flag an owner and a removal date, and delete release flags after full rollout.
Common mistakes
- Hard-coding the model name and prompt text, so every change needs a deploy.
- Using one flag for the whole assistant and calling it control.
- Letting a failed flag lookup default to enabled for write tools.
- Leaving fully launched release flags in the code for months.
Check yourself · 2 of 3
The flag service times out. What should the code do for a tool that can send customer emails?
Check yourself · 3 of 3
A release flag has been at 100% of users for four months. What should the team do?
Practice items, not counted towards your mastery.
Start here
- Feature Toggles (martinfowler.com) (opens in a new tab)ArticleFree
Release, ops and permission toggles, and why stale toggles must be removed.
- Canarying releases (Google SRE Workbook) (opens in a new tab)BookFree
How to size, time and judge a canary against a control population.
- OpenFeature (opens in a new tab)ToolFree
A vendor-neutral flag API, so evaluation code does not depend on one flag provider.