Effective Context for AI: Prompt Engineering
Table of Contents
🧠 Context is King
The single biggest factor in the quality of AI output is the quality of the input (context). An LLM is a completion engine. If you give it vague context, it hallucinates. If you give it specific context, it reasons.
The 4 C’s of Context
- Capacity: The role (Act as a Senior Android Engineer).
- Context: The background (Project is MVVM, Hilt, Room).
- Constraints: The rules (Use Kotlin, no Java, handle errors with Result).
- Chain of Thought: The process (Think step-by-step).
📝 Example: The Bad Prompt
“Create a login screen.”
Result: A generic XML layout, probably using RelativeLayout or LinearLayout, maybe in Java.
🚀 Example: The Good Prompt
“Act as a Senior Android Developer. Create a Login Screen using Jetpack Compose (Material 3).
Context:
- Use Hilt for DI.
- ViewModel should expose
StateFlow<LoginUiState>.- Handle loading, success, and error states.
Constraints:
- Use
OutlinedTextFieldfor inputs.- Validate email format.
- Do NOT use LiveData.
Steps:
- Define
LoginUiState.- Create
LoginViewModel.- Implement
LoginScreencomposable.”
Result: Production-ready code that fits your architecture.
🛠️ Optimizing Context Windows
Don’t paste 50 files. Be selective.
- Relevant Files Only: Paste the ViewModel and the Repository interface, not the whole
datalayer. - Summarize: Instead of pasting a 2000-line file, say “User model has id, name, email.”
🤖 Advanced Technique: Few-Shot Prompting
Show, don’t just tell. Give examples of desired output.
“Convert this JSON to a Kotlin Data Class.
Example: Input:
{"id": 1, "name": "John"}Output:@Serializable data class User(val id: Int, val name: String)Now convert this: …”
🏁 Conclusion
Prompt Engineering is the new coding. Writing effective prompts is a skill that separates average developers from 10x AI-augmented engineers.
You might also be interested in
Power Up Your AI Agents with Skills: From Gemini to Copilot
Discover how to transform your generalist AI assistant into a team of specialists using Agent Skills. Includes practical examples for Android, Kotlin, and Conventional Commits.
ChatGPT 5.3 Codex: The New Standard for Mobile Development?
A deep dive into ChatGPT 5.3 Codex, its new dedicated app, and what it means for Android developers. Includes comparison with Gemini 3.0 Pro.
AI Skills in Development: Powering Your Android Workflow
Discover how AI Skills transform modern development, automating complex tasks and improving productivity in Android projects.