The idea
A feature flag is a runtime switch your code checks: if flags.enabled("new_reranker", user): ... You can turn features on for internal users, a percentage of users or specific customers, and turn them off instantly if something breaks, all without a deploy.
For AI products, flags control prompt versions, model choices, new tools for agents and expensive features. They pair with A/B tests: the flag decides the variant, analytics compares outcomes.
Clean up flags after rollout; old flags become hidden complexity.
It separates deploying code from releasing features, which makes both safer.
Words to know
- Kill switchA flag that disables a feature immediately.
Try it without code
List flag candidates
- List 3 upcoming changes in your app.
- For each, decide who should get it first.
Use it in code
A minimal percentage-rollout flag store backed by a JSON file or Redis.
import hashlib, json
FLAGS = json.loads('{"new_reranker": {"enabled": true, "percent": 20, "allow": ["staff@ourco.ie"]},'
' "agent_email_tool": {"enabled": false}}')
def enabled(flag, user_id):
f = FLAGS.get(flag, {})
if not f.get("enabled"): return False
if user_id in f.get("allow", []): return True
bucket = int(hashlib.md5(f"{flag}:{user_id}".encode()).hexdigest(), 16) % 100
return bucket < f.get("percent", 0)
print(enabled("new_reranker", "user-9"), enabled("agent_email_tool", "user-9"))Put your reranker behind a flag and enable it for 20% of users.
Common mistakes
- Flags that live forever.
- Flag checks scattered with inconsistent user IDs.