Skip to content
DenseChip
Learn
PracticeCode labInterview

DenseChip

Navigate

Menu

LearnPracticeCode labInterview

Tools

All toolsSV editorCode repoResume
DenseChip

Practice, courses, and chip-design tools in one focused workspace.

LearnPracticeCode labInterviewToolsLearning paths

© 2026 DenseChip

AboutContactPrivacyTerms
Skip to lesson

Course contents

  • Getting Started with AI for VLSI Engineers5
  • Just Enough AI: Models and Context15
  • Prompting13
    • Anatomy of a Prompt
      • Five Parts of a Prompt
      • Roles: System, User, and Assistant
      • Specific and Parseable
      • Weak Versus Strong Prompts
      • Prompt Template Builder
    • Examples and Reasoning
    • Prompt Debugging
  • Trust and Verification14
  • Using AI for Engineering Work17
  • Engineering Walkthroughs7
  • Practical Foundations for AI Workflows4
  • Engineering Data5
  • Retrieval-Augmented Generation6
  • Agents and Tool Use18
  • Agent Design8
  • MCP and Skills6
  • Multi-Agent Design6
  • Practical Capstone6
  • Tokens, Cost and Latency12
  • Agentic Workflows for Chip Teams18
  • Interview and Judgment10
  • AI Skills: Full Course Index
  • Working with AI Glossary
  • Working with AI Cheatsheet
Loading lesson

‹Anatomy of a Prompt
  1. Topics
  2. AI Skills for VLSI Engineers
  3. Prompting
  4. Anatomy of a Prompt
  5. Prompt Template Builder

Asking Clearly · Beginner to Intermediate

Prompt Template Builder

A small template builder that assembles five sections and checks a token budget.

On this page

    Builder shape

    The builder joins five fixed sections in one order. Fixed order keeps diffs small when one section changes.

    It calls no model. It assembles text and checks shape before anything is sent.

    Section

    Builder rule

    Gate

    task

    One verb phrase plus scope.

    Non-empty.

    context

    Facts that change the answer.

    Non-empty.

    constraints

    Limits and forbidden actions.

    Names at least one bound.

    format

    Keys and separator.

    Mentions KEY: VALUE.

    examples

    One normal case plus one edge.

    Contains Example.

    Token estimate and budget check

    Common tokenizers use subword units similar to BPE. A rough planning rule is about 4 characters per token for English prose with common tokenizers, with fewer characters per token for code, numbers, hex, and non-Latin text.

    The rule is approximate and tokenizer-dependent. Behavior varies by model: measure it on real prompts before trusting a budget.

    example.py
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    import sys
    
    def estimate_tokens(text):
        return (len(text) + 3) // 4
    
    def build_prompt(sections):
        order = ["task", "context", "constraints", "format", "examples"]
        parts = []
        for key in order:
            parts.append(key.upper() + ":\n" + sections[key])
        return "\n\n".join(parts)
    
    def main():
        sections = {
            "task": "Explain what the FIFO block does in two sentences.",
            "context": "8-deep FIFO, active-low reset, used between UART RX and core.",
            "constraints": "No generic advice. Name signals. Stay under 120 words.",
            "format": "Return lines as KEY: VALUE with keys FUNCTION, DEPTH, SIGNALS.",
            "examples": "Example input: full flag high. Example output: FUNCTION: backpressure.",
        }
        budget = 500
        for key in ["task", "context", "constraints", "format", "examples"]:
            if key not in sections or sections[key].strip() == "":
                print("FAIL: missing section text")
                sys.exit(1)
        prompt = build_prompt(sections)
        for tag in ["TASK:", "CONTEXT:", "CONSTRAINTS:", "FORMAT:", "EXAMPLES:"]:
            if tag not in prompt:
                print("FAIL: section tag absent")
                sys.exit(1)
        if "KEY: VALUE" not in prompt:
            print("FAIL: parseable marker absent")
            sys.exit(1)
        total = estimate_tokens(prompt)
        if total <= 0 or total > budget:
            print("FAIL: total outside budget")
            sys.exit(1)
        print("PASS: 5 sections assembled within 500 token budget")
    
    main()

    Worked budget numbers

    The program prints one PASS line with its counts. The calc block below works the same arithmetic by hand on stated example sizes.

    plaintext
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    example budget check with stated section sizes
    budget = 500 tokens at a planning rule of 4 characters per token
    task 160 chars -> 40 tokens, context 640 chars -> 160 tokens
    constraints 320 chars -> 80 tokens, format 160 chars -> 40 tokens
    examples 480 chars -> 120 tokens
    total chars = 160 + 640 + 320 + 160 + 480 = 1760
    total tokens = 40 + 160 + 80 + 40 + 120 = 440 tokens
    headroom = 500 - 440 = 60 tokens
    headroom share = 60 / 500 = 0.12 = 12%
    440 <= 500, so the prompt fits the budget

    Common mistakes

    In the basic attention form, cost grows with the square of the sequence length, and efficient variants exist. Long inputs are less reliable than short ones, with a reported tendency to use the start and end better than the middle.

    Trimming context to the deciding facts therefore serves both budget and reliability. Measure hit rate on the task after each trim.

    Common pitfall

    Counting characters by eye and skipping the builder gate lets one long example push the prompt over budget. Run the builder check on every edit, not just the first draft.

    Interview

    Likely probes: builder gates and budget trade-offs.

    • Five fixed sections in fixed order with non-empty gates plus a format marker.

    • Rough tokens are characters divided by 4, approximate and tokenizer-dependent.

    • Trimming keeps the deciding facts; each trim is followed by a task measurement.

    Check yourself The builder reports a total above budget after an example is added. What is the first fix?

    Shorten or drop the lowest-value section first, usually the longest example. Re-run the gate until the total fits.

    Check yourself In the worked calc, the total is 440 tokens against a 500 budget. What is the headroom in tokens and percent?

    60 tokens. That is 12% of the budget.

    Related topics

    • Five parts of a prompt

    • Cost arithmetic

    Previous

    25 / 173

    Next: Examples and Reasoning

    Up next

    Up nextExamples and Reasoning

    Sign in to save progress

    Practice this lessonReport an error

    See also

    • Five Parts of a Prompt
    • Roles: System, User, and Assistant
    • Specific and Parseable