ChatBot.prompt_builder

Create an attention-optimized prompt builder for declarative prompt composition.

USAGE

ChatBot.prompt_builder(builder_type='general')

This method returns a specialized prompt builder that implements attention-based structuring principles from modern prompt engineering research. The builder helps engineers create prompts with optimal attention patterns through a fluent, declarative API.

Based on research showing that structure matters more than specific word choices, this builder enables you to:

  • front-load critical information (primacy bias)
  • create structured sections for clear attention clustering
  • avoid attention drift through specific constraints
  • build modular, maintainable prompt components

Parameters

builder_type : Union[str, BuilderTypes] = 'general'

Type of prompt builder to create. You can use either a string or a constant from BuilderTypes for better autocomplete and type safety.

Returns

PromptBuilder

A prompt builder with methods for declarative prompt composition.

Available builder types

The following builder types are available:

  • BuilderTypes.GENERAL or "general": basic attention-optimized builder
  • BuilderTypes.ARCHITECTURAL or "architectural": pre-configured for code architecture analysis
  • BuilderTypes.CODE_REVIEW or "code_review": pre-configured for code review tasks
  • BuilderTypes.DEBUGGING or "debugging": pre-configured for debugging assistance

Examples


Basic attention-optimized prompt building

import talk_box as tb

bot = tb.ChatBot().model("gpt-4-turbo")

# Build an attention-optimized prompt
prompt = (bot.prompt_builder()
    .persona("senior software architect", "comprehensive codebase analysis")
    .task_context("Create architectural documentation")
    .critical_constraint("Focus on identifying architectural debt")
    .core_analysis([
        "Tools, frameworks, and design patterns",
        "Data models and API design patterns",
        "Architectural inconsistencies"
    ])
    .output_format([
        "Use clear headings and bullet points",
        "Include specific examples from codebase"
    ])
    .final_emphasis("Prioritize findings by impact and consistency")
    .build())

# Use the structured prompt
response = bot.chat(prompt)

Pre-configured builders for common tasks

# Architectural analysis with pre-configured structure
arch_prompt = (bot.prompt_builder(tb.BuilderTypes.ARCHITECTURAL)
    .focus_on("identifying technical debt")
    .build())

# Code review with attention-optimized structure
review_prompt = (bot.prompt_builder(tb.BuilderTypes.CODE_REVIEW)
    .avoid_topics(["personal criticism"])
    .focus_on("actionable improvement suggestions")
    .build())

Preview prompt structure before building

builder = (bot.prompt_builder()
    .persona("technical advisor")
    .core_analysis(["Security", "Performance", "Maintainability"])
    .output_format(["Structured sections", "Specific examples"]))

# Preview the attention structure
structure = builder.preview_structure()
print(f"Estimated tokens: {structure['estimated_tokens']}")
print(f"Priority sections: {len(structure['structured_sections'])}")

# Build when satisfied with structure
prompt = builder._build()

Notes

The returned builder implements attention-based principles:

  • Primacy bias: critical information is front-loaded
  • Structured sections: clear attention clustering prevents drift
  • Personas: behavioral anchoring for consistent responses
  • Specific constraints: avoid vague instructions that cause attention drift
  • Recency bias: final emphasis leverages end-of-prompt attention

See Also

PromptBuilder : The full prompt builder API preset : Use presets for quick specialized configurations persona : Set behavioral context for responses