Skip to content

    Prompt Engineering

    AI · Beginner

    Definition

    Prompt engineering is writing clear instructions and context so an LLM produces the desired output.

    Better prompts give more accurate and consistent AI results.

    Diagram

    RoleContextTaskFormatExamples

    Flowchart

    State the roleGive contextSpecify the taskDefine output formatAdd examples

    Example: Structured prompt

    prompt = '''You are a DSA tutor.
    Explain binary search in 3 bullet points.
    Return markdown.'''
    print(len(prompt.splitlines()))

    Output: 3

    Key points

    • Few-shot examples improve accuracy
    • Ask for step-by-step reasoning on hard tasks

    Interview questions

    Zero-shot vs few-shot?

    Zero-shot gives no examples; few-shot includes a few input-output examples.

    More AI topics