What is prompt engineering?

Prompt engineering is the craft of structuring the input to an LLM to reliably produce the output you need. It covers instruction clarity, few-shot examples, persona setting, output format specification, chain-of-thought elicitation, and constraint setting. It is iterative — treat prompts like code and version-control them.

CoT prompting asks the model to reason step-by-step before giving its final answer. Adding ‘Let’s think step by step’ or providing worked-example reasoning in few-shot demonstrations significantly improves performance on multi-step maths, logic, and coding tasks.

RAG combines a retrieval system (vector database + embeddings) with an LLM. At query time, relevant documents are fetched and injected into the prompt, grounding the model’s response in up-to-date or proprietary data without retraining. It is the dominant pattern for knowledge-intensive applications.

Hallucinations stem from the model generating plausible-sounding but unfounded text. Mitigations: use RAG to ground responses in retrieved sources, instruct the model to say ‘I don’t know’, request citations, lower temperature, add consistency checks, and implement human-in-the-loop review for high-stakes outputs.

The system prompt is an instruction block passed before the conversation that sets the model’s persona, rules, output format, and constraints. Use it to define the model’s role, specify response format (JSON, markdown), set tone, list hard constraints, and provide background context that applies to every turn.