Updating models and prompts in production
Why it matters
- Prompt engineering is iterative; hardcoding strings leads to constant app store submissions.
- Model availability and IDs change frequently; your app must be decoupled from specific versions.
- A bad prompt can break your entire UX; you need the ability to roll back instantly.
- Interviewers look for your ability to manage non-deterministic features in a deterministic release cycle.
The simple explanation
- A restaurant menu that changes daily.
- The kitchen (the server) decides what is available.
- The waiter (the Android app) just delivers the menu to the customer.
- If a dish is bad, the manager changes the menu without rebuilding the restaurant.
In production AI features, you must decouple the application logic from the model configuration. If you hardcode a specific model ID or a prompt string in your Kotlin code, you lose the ability to respond to model drift, outages, or performance regressions.
Instead, use a configuration pattern. The Android app fetches a configuration object from a server or a service like Firebase Remote Config at startup or during a background sync. This object contains a version, the model_id, the system_prompt, and temperature settings. If the app calls your own backend, the prompt and model can live only on the server and the app just names the feature.
| Component | Responsibility | Storage |
|---|---|---|
| App Logic | Handles UI, networking, and error states | Local APK |
| Prompt/Model Config | Defines the 'personality' and engine | Server/Remote Config |
| API Key | Authenticates the request | Server-side only |
When a new model version is released or a prompt needs tuning to fix a safety issue, you update the value in your remote dashboard. The behavior changes the next time the app fetches and activates the config (Remote Config caches values, so this is not instant for every user; server-side config changes faster). This allows for 'Canary Releases' where you serve a new prompt to only a subset of users (Remote Config supports percentage rollouts and conditions) to monitor for increased error rates or poor user feedback before a full rollout.
Notes
- Never hardcode model names or API keys in your Android source code.
- Use Remote Config or server config to manage prompts and model identifiers so you can roll back without a release.
- Version your configurations so the app knows if it is using an outdated prompt format.
- Implement a fallback mechanism in case the remote configuration fails to fetch.
- Always keep API keys on your backend; the Android app should call your server, not the LLM provider directly.
- Monitor 'retry rates' and 'thumbs down' metrics immediately after a prompt update.
- On-device models are downloaded and versioned separately from the APK, not through normal app updates.
- Before a rollout, score the new prompt or model on your fixed eval set.
Code example
This example demonstrates a configuration provider that fetches AI settings from a remote source and provides a safe fallback for the app to use.
data class AiConfig(
val version: Int,
val modelId: String,
val systemPrompt: String,
val temperature: Double
)
class AiRepository(
private val remoteConfig: RemoteConfigProvider
) {
// Default config used if network fails or config is missing
private val fallbackConfig = AiConfig(
version = 1,
modelId = "default-model",
systemPrompt = "You are a helpful assistant.",
temperature = 0.7
)
suspend fun getActiveConfig(): AiConfig {
return try {
// In a real app, this fetches from Firebase or your API
remoteConfig.fetchConfig() ?: fallbackConfig
} catch (e: Exception) {
fallbackConfig
}
}
suspend fun generateResponse(userInput: String) {
val config = getActiveConfig()
// Logic to call your backend using config.modelId and config.systemPrompt
println("Using model: " + config.modelId)
println("Prompt: " + config.systemPrompt)
}
}
interface RemoteConfigProvider {
suspend fun fetchConfig(): AiConfig?
}- The
fallbackConfigkeeps the app working when the fetch fails or the value is missing. In production, keep the last fetched config too (Remote Config does this for you), so the fallback is rarely used. - The
versionfield goes into your logs and metrics, so you can tell which prompt produced which result. - The
AiRepositoryabstracts the source of truth from the UI layer. - The
RemoteConfigProviderinterface allows for easy testing with mocks.
Run the idea in plain Kotlin
data class AiConfig(
val version: Int,
val modelId: String,
val systemPrompt: String,
val temperature: Double
)
interface ConfigProvider {
fun fetchConfig(): AiConfig?
}
class FakeProvider(private val value: AiConfig?, private val fail: Boolean) : ConfigProvider {
override fun fetchConfig(): AiConfig? {
if (fail) throw RuntimeException("network down")
return value
}
}
class AiRepository(private val provider: ConfigProvider) {
private val fallbackConfig = AiConfig(1, "fallback-model", "Be brief.", 0.5)
fun getActiveConfig(): AiConfig {
return try {
provider.fetchConfig() ?: fallbackConfig
} catch (e: Exception) {
fallbackConfig
}
}
}
fun main() {
val remote = AiConfig(7, "model-from-config", "You are a poet.", 0.9)
val ok = AiRepository(FakeProvider(remote, false)).getActiveConfig()
println("Remote: v" + ok.version + " " + ok.modelId)
val missing = AiRepository(FakeProvider(null, false)).getActiveConfig()
println("Missing: v" + missing.version + " " + missing.modelId)
val broken = AiRepository(FakeProvider(remote, true)).getActiveConfig()
println("Fetch failed: v" + broken.version + " " + broken.modelId)
}In production
- Users reported the AI giving incorrect medical advice.
- A recent update to the underlying LLM changed how it interprets instructions.
- The hardcoded prompt was no longer sufficient for the new model version.
- The team updated the system prompt via Remote Config to include stricter constraints.
- The new prompt was tested against a fixed evaluation set.
- The change was rolled out to a subset of users first to verify the fix.
- A developer accidentally committed a direct LLM API key to the Git repository.
- Automated bots detected the key and began exhausting the company's credit quota.
- The app started throwing 429 Too Many Requests errors for all users.
- The key was immediately revoked in the provider dashboard.
- The architecture was changed to route all AI requests through a secure backend proxy.
- The Android app now only holds a session token, never the provider key.
Common mistakes
- Hardcoding model IDs. If the model is deprecated or undergoes a breaking change, you must release a new app version to fix it.
- Storing API keys in BuildConfig. Decompiling an APK can reveal these keys, leading to unauthorized usage and cost spikes.
- Updating prompts without evaluation. A prompt that works for one task might cause regressions in another, breaking existing features.
- No fallback configuration. If the user is offline or the config service is down, the AI feature has nothing to run with and can crash.
- Using a single global prompt for all users. You lose the ability to perform A/B testing or canary rollouts for new model behaviors.
Interview questions
Answer out loud first. Then reveal the answer and compare it at each depth.
“How do you handle updates to the AI model or prompts in a production Android app?”
“Where should LLM API keys be stored in an Android application?”
“What happens if you update a prompt and the AI starts behaving unexpectedly?”
“Why shouldn't you hardcode a specific versioned model name in your Kotlin code?”
Quiz
What is the primary benefit of using Remote Config for AI prompts?
Where is the safest place to store a sensitive LLM API key?
If a remote configuration fetch fails, what should the Android app do?
What is a 'Canary Release' in the context of AI features?
0 of 4 answered
Mini task
Task: Implement a Safe AI Configuration Provider
Goal: Create a Kotlin class that manages AI configurations with a fallback mechanism.
- Define a Data Class: Create an
AiConfigdata class withversion(Int),modelId(String),systemPrompt(String), andtemperature(Double). - Create an Interface: Define
ConfigProviderwith a functionfetchConfig(): AiConfig?. - Implement the Repository: Create an
AiRepositoryclass that takes aConfigProviderin its constructor. - Implement Fallback Logic: Inside
AiRepository, create a functiongetEffectiveConfig(). It should attempt to callfetchConfig(). If the result isnullor an exception is thrown, it must return a hardcoded 'default'AiConfigobject. - Test it: In a
mainfunction, create aMockProviderthat returnsnull. Verify thatgetEffectiveConfig()returns your default values instead of crashing.
Done Condition: The code compiles and the main function prints the modelId of the fallback configuration when the provider returns null.