Click any question to reveal the answer. Questions are grouped by difficulty.
Prompt engineering is the practice of designing and refining inputs to LLMs to elicit desired outputs. It matters because LLMs are highly sensitive to how instructions are framed. Good prompts can dramatically improve output quality, accuracy, and relevance without any model changes, making it a cost-effective alternative to fine-tuning for many use cases.
Zero-shot gives the model a task description without examples. One-shot includes one example of the expected input-output pair. Few-shot provides multiple examples to establish the pattern. Few-shot typically improves performance on complex or ambiguous tasks by helping the model understand the desired format and reasoning style through demonstration.
The system prompt sets the AI's behaviour, persona, and constraints across the conversation. User prompts contain the human's messages and queries. Assistant prompts contain the AI's responses and can be pre-filled to guide output format. This separation enables consistent behaviour while allowing dynamic user interactions. Most API providers support this three-role structure.
Temperature controls output randomness. Use low temperature (0-0.3) for factual, deterministic tasks like classification and extraction. Use higher temperature (0.7-1.0) for creative tasks like brainstorming. Top-p and top-k further shape the probability distribution. These parameters interact with prompt design; well-constrained prompts can tolerate higher temperatures.
Delimiters (like triple backticks, XML tags, or separators) clearly mark boundaries between instructions, context, and user input. They prevent prompt injection by isolating user-provided content, improve parsing of structured prompts, and help the model distinguish between what to process and how to process it. Consistent delimiter usage improves output reliability.
Temperature controls randomness by scaling logits before softmax; lower values make output more deterministic. Top-k sampling restricts selection to the k most probable tokens. Top-p (nucleus sampling) selects from the smallest set of tokens whose cumulative probability exceeds p. These parameters trade off between creativity and coherence.
Hallucination occurs when LLMs generate plausible-sounding but factually incorrect information. It happens because LLMs are trained to predict probable next tokens, not verified facts. Mitigation strategies include RAG for grounding in verified sources, chain-of-thought prompting, constrained decoding, and implementing fact-checking pipelines.
In-context learning is the ability of LLMs to learn new tasks from examples provided in the prompt without updating model weights. Fine-tuning permanently modifies model weights through gradient descent on task-specific data. In-context learning is faster and more flexible but limited by context window size and generally less reliable for complex tasks.
Chain-of-thought prompting instructs the model to show its reasoning step by step before giving the final answer. It is most effective for complex reasoning tasks like math, logic, multi-step analysis, and code debugging. Adding 'Let's think step by step' or providing worked examples significantly improves accuracy on tasks requiring multi-step reasoning.
Define the role (banking support agent), scope (account queries, transactions, card services), tone (professional, helpful, in English and Hindi). Include guardrails against providing financial advice or sharing account details in responses. Specify escalation paths for complaints. Include context about Indian banking terminology (UPI, NEFT, RTGS) and RBI regulations relevant to customer interactions.
Prompt injection occurs when user input manipulates the LLM into ignoring its system instructions or performing unintended actions. Defences include separating system and user prompts with clear delimiters, input sanitisation, output validation, using structured output formats, implementing allowlists for permitted actions, and layered defence with multiple validation steps.
Specify the exact schema in the prompt with examples. Use delimiters like code blocks to frame the output. Many APIs support function calling or structured output modes that constrain generation to valid JSON. Implement parsing with error handling and retry logic. For critical applications, validate against a JSON schema and use type-safe parsing libraries.
ReAct combines reasoning (thinking about what to do) and acting (taking actions like tool calls) in an interleaved fashion. The model reasons about the problem, decides on an action, observes the result, and repeats. This pattern powers most AI agent frameworks and is more reliable than pure reasoning because it grounds decisions in real observations.
Create a diverse test set of inputs with expected outputs. Measure quantitative metrics (accuracy, relevance scores, format compliance). Use LLM-as-judge for qualitative evaluation. Track prompt versions systematically. A/B test in production. Iterate by analysing failure cases and refining instructions. Tools like promptfoo, LangSmith, and Braintrust help automate this process.
Prompt templates are parameterised prompts with placeholders filled at runtime (e.g., 'Summarise this {document_type} in {language}'). In production, manage them as versioned configuration with template engines like Jinja2. Store in a prompt registry, track performance per version, and implement rollback capability. LangChain and similar frameworks provide prompt template abstractions.
Provide 3-5 diverse examples per category covering Indian telecom issues (network outages, billing disputes, SIM-related, data pack queries, number portability). Include edge cases and examples in both English and Hinglish. Structure examples with clear input-output pairs. Add instructions for ambiguous cases and a fallback 'Other' category. Test with regional variations.
Strategies include chunking the document and processing each chunk separately, using map-reduce patterns (summarise chunks then synthesise), implementing rolling summaries, using RAG to retrieve only relevant sections, and leveraging models with longer context windows. Choose based on whether the task needs global context (use map-reduce) or local information (use RAG).
Prompt engineering crafts inputs to guide a model's existing capabilities without changing weights. Instruction tuning fine-tunes the model on instruction-following data to make it inherently better at following prompts. Instruction-tuned models (ChatGPT, Claude) respond better to natural language prompts compared to base models that require more carefully engineered prompts.
Instruct the model to only use provided context and say 'I don't know' when uncertain. Use structured extraction from grounding documents rather than open generation. Ask for citations or evidence. Implement confidence scoring in the output format. Use chain-of-thought to make reasoning transparent. Combine with RAG for factual grounding.
Be specific about the role, capabilities, and limitations. Define the output format explicitly. Provide examples of good and bad responses. Set clear boundaries on what the model should and should not do. Use numbered steps for complex tasks. Place the most important instructions at the beginning and end (primacy/recency effect). Keep instructions concise and unambiguous.
Specify the programming language, framework, and version. Describe the function signature, inputs, outputs, and edge cases. Provide relevant context like existing code patterns and constraints. Ask for error handling and comments. Include test cases the code should pass. Use few-shot examples of similar functions. Request explanations of key design decisions.
Remove redundant instructions and examples. Use concise, precise language. Cache common prompt prefixes where the API supports it. Replace verbose few-shot examples with clear instructions when possible. Use shorter output formats (abbreviations, codes instead of full text). Batch similar requests. Evaluate whether a smaller, cheaper model suffices for the task.
Prompt chaining breaks a complex task into sequential simpler prompts where each output feeds the next. A single complex prompt tries to handle everything at once. Chaining is more reliable for multi-step tasks, easier to debug, and allows different models or parameters per step. Single prompts are faster and cheaper but may fail on complex reasoning.
Function calling is a structured way for LLMs to indicate they want to invoke a specific function with typed arguments, returning JSON matching a schema. Tool use is a broader concept where the model selects from available tools and generates appropriate calls. Function calling is a specific implementation of tool use. Both enable LLMs to interact with external systems reliably.
Query decomposition breaks a complex question into simpler sub-questions, retrieves information for each, and synthesises the results. Use it when questions require information from multiple domains or documents. For example, 'Compare the AI policies of India and the US' decomposes into separate retrievals for each country's policy, then a comparison synthesis step.
Include source metadata (date, authority, reliability) with retrieved chunks. Instruct the LLM to identify and flag contradictions. Prioritise more recent or authoritative sources. Present multiple viewpoints when appropriate. Implement a confidence scoring mechanism. For critical applications, surface contradictions to users rather than silently choosing one version.
Include source metadata (document title, page, URL) with each chunk. Instruct the LLM to reference specific sources using identifiers. Parse citations from the output and validate them against retrieved chunks. Display inline citations with links to source documents. For accuracy, use structured output to separate the answer from citations and validate each reference.
Write clear, specific descriptions that explain what the tool does, when to use it, and what inputs it expects. Include parameter descriptions with examples. Specify constraints and valid values. Add negative instructions (when NOT to use the tool). Use consistent naming conventions. Test with actual LLMs to verify they invoke tools correctly in various scenarios.
MCP prompts are pre-defined interaction templates exposed by servers that users can select to initiate specific workflows. They can include dynamic arguments and generate structured messages with roles. Unlike system prompts which set global behaviour, MCP prompts are task-specific templates that combine instructions, context, and tool usage patterns for common operations.
ReAct (Reasoning + Acting) interleaves thinking and doing in a loop: Thought (reason about the situation), Action (select and execute a tool), Observation (process the result). The agent continues this cycle until it reaches the goal or determines it cannot proceed. This pattern grounds reasoning in real observations and is the foundation of most production agent frameworks.
Reflection is when an agent critiques its own output or reasoning before finalising. The agent generates a response, then evaluates it against criteria like accuracy, completeness, and relevance. If the evaluation identifies issues, the agent revises its approach. This self-improvement loop can significantly enhance output quality at the cost of additional LLM calls.
Self-consistency generates multiple reasoning paths for the same question using sampling (higher temperature) and selects the most common answer via majority voting. It improves reliability on reasoning tasks by reducing the impact of individual reasoning errors. It increases cost proportionally to the number of samples but can significantly boost accuracy on complex tasks.
Break extraction into stages: first identify document type (Aadhaar, PAN, invoice), then extract specific fields per type. Use structured output format with field-level confidence scores. Handle multiple Indian scripts and transliterations. Provide examples of each document type. Include validation rules (PAN format: ABCDE1234F, Aadhaar: 12 digits). Chain extraction and validation prompts.
Tree-of-thought (ToT) explores multiple reasoning branches simultaneously, evaluates partial solutions, and backtracks from unpromising paths. Unlike linear chain-of-thought, ToT considers alternative approaches and self-evaluates. It is particularly useful for complex planning, puzzle-solving, and creative tasks where the first reasoning path may not be optimal.
Constitutional AI uses a set of principles (a constitution) to guide model behaviour through self-critique and revision. The model generates responses, critiques them against the constitution, and revises accordingly. In prompt engineering, similar principles can be embedded in system prompts to create self-correcting behaviour without explicit human feedback on each response.
Chain 1: Extract structured data (name, education, skills, experience, certifications). Chain 2: Score against job requirements (tech stack match, years of experience, education level). Chain 3: Generate a summary highlighting strengths and gaps. Include Indian education system context (IIT/NIT/IIIT tiers, GATE scores, Indian certifications). Handle varied resume formats and Indianised English.
Use the target language for examples and instructions when the model supports it. Handle code-mixing (Hinglish, Tanglish) explicitly. Test tokenisation efficiency for non-Latin scripts. Provide transliterated alternatives. Use language-specific formatting conventions. Test output quality in each language separately and adjust temperature. Consider language-specific evaluation metrics.
Route a percentage of traffic to each prompt variant. Define clear metrics (accuracy, user satisfaction, latency, cost). Ensure sufficient sample size for statistical significance. Log all inputs, outputs, and metadata. Use automated evaluation with LLM judges plus manual review of edge cases. Implement gradual rollout with rollback capability. Monitor for regression over time.
Meta-prompts are prompts designed to generate or optimise other prompts. You describe the task and constraints to an LLM and ask it to produce an effective prompt. This is useful for rapid prototyping, discovering non-obvious prompting strategies, and automating prompt optimisation. Tools like DSPy automate this meta-prompting process with optimisation algorithms.
Specify the legal domain (corporate, criminal, tax under Indian statutes). Instruct the model to preserve legal terminology and statutory references accurately. Include disclaimers that summaries are not legal advice. Structure output with key findings, relevant sections/acts, and actionable items. Handle references to Indian acts (IT Act, Companies Act) and court hierarchies. Test against verified legal summaries.
Create a test suite of known injection attacks: direct instruction override, indirect injection through context, encoding-based attacks, and multi-step manipulation. Measure the rate at which the model follows injected instructions versus maintaining its original behaviour. Test regularly as new attack patterns emerge. Implement continuous monitoring in production for unusual output patterns.