SarvamStack

    Week 2–3

    Prompt engineering

    The art of getting LLMs to behave. System prompts, few-shot examples, and structured outputs — without changing a single weight.

    Pause & reflect

    Before you read on, answer this in your head — or on paper:

    A model has billions of parameters. You send it text. It generates more text.

    How do you think the model "understands" your instructions? It never learned your company's style guide or your JSON schema in training. So what makes it follow them — or not?

    Take about 25 seconds. No skipping — thinking first makes the next part stick.

    You don't need to fine-tune to get useful behaviour. A well-crafted prompt can define role, tone, format, and constraints. The model interprets it at inference time. Iterate fast — change the prompt, run again, no training cycle. The best engineers treat prompting as an iterative, test-driven process.

    Before you continue: Before we show techniques: when might a few-shot example outperform a long paragraph of instructions? When might it fail?Pause 20s. Then read on.

    System prompt

    Sent once, before user messages. Sets role ("You are a helpful coding assistant"), tone (formal, casual), and rules ("Always respond in JSON"). The model treats it as global context. Put critical instructions at the start and end — models often weight those positions more.

    Few-shot

    Show 1–5 input→output examples. The model infers the pattern. Often more reliable than long instructions. Useful for: format consistency, domain jargon, edge-case handling. One strong example can outperform a paragraph of abstract rules.

    Structured output

    Ask for JSON, XML, or use function-calling. Makes responses parseable and downstream code simpler. Most APIs support response_format or similar. Essential for production pipelines.

    Chain-of-thought

    Request reasoning steps: "Think step by step" or "Show your work." Improves accuracy on maths, logic, coding. Costs more tokens but often worth it for hard problems. Use when the task benefits from explicit reasoning.

    Test your understanding

    Don't reveal yet. Think for ~30 seconds first — what would you try?

    You want the model to output a list of items in JSON format. The model sometimes adds extra text before or after the JSON. How can you reduce this in your prompt?

    Check your understanding

    ?

    When is chain-of-thought prompting most beneficial?

    ?

    What does a system prompt primarily control?

    ?

    Few-shot prompting means:

    ?

    What is the main advantage of structured output (JSON, function-calling)?