Write effective prompts for Bob
Maximize Bob's output by writing effective prompts.
IBM Bob is a coding and technology assistant, however Bob can't read your mind. Bob relies on your directions to deliver great results. Learning the basics of prompt writing enhances your experience with Bob, saving you time and giving you what you want.
What is a prompt?
A prompt is a set of instructions that you give to Bob to get the output you want. A prompt can be a question, a request, or a command. It can be as simple as "What is the capital of France?" or as complex as "Write a Python function that takes a list of numbers and returns the average."
Think of the software development principles of "garbage in, garbage out". If you give Bob a vague or incomplete prompt, you might get a vague or incomplete answer.
When you write higher quality prompts, you get higher quality responses. A good prompt is clear, specific, and provides enough context for Bob to understand what you want.
Prompt components
To write an effective prompt, you should include the following components:
- Instruction: Directs Bob on what task to perform. The instruction is written as a clear command such as “Summarize this Python function" or “Generate an SBOM for this API.” Strong instructions reduce ambiguity and lead to more relevant results.
- Role: Assigns Bob a specific role or persona to adopt when generating the response. For example, you might say "You are a senior software engineer with expertise in Python." This helps Bob tailor its response to fit the perspective of that role.
- Context: Context provides additional background or details that shape Bob’s response. The context might include a description of the situation, tone, audience, or key information you want incorporated. Context helps Bob stay aligned with the task.
- Example: Examples include one or more examples that demonstrate the desired pattern, format, or tone. Providing examples is especially useful when you want the output to follow a specific style or structure. Examples help Bob interpret what a good response means.
- Cues: A cue is a brief piece of text that leads into the type of response you want. Cues are often placed at the end of the prompt to nudge Bob’s output generation in the right direction.
As you hone your prompt writing skills, you can save your prompts in a file to reuse, and share with your team.
Prompt best practices
The following best practices can help you write effective prompts for Bob.
- Be specific: The more specific your prompt, the better Bob can understand what you want. Instead of asking "How do I write a Python function?", ask "How do I write a Python function that takes a list of numbers and returns the average?"
- Provide context: If your prompt is about a specific project or codebase, provide some context about it. This helps Bob generate a response that is relevant to your situation. Use Bob @ context mentions to reference specific files.
- Break down tasks: Like you would when refining a task in your backlog, break down complex tasks into smaller, more manageable steps. This can help Bob generate more accurate and focused responses.
- Include examples: If you are adding a new API, direct Bob to review well written API's in your codebase to use as examples. You can also include examples in your prompt to show Bob the format or style you want.
Write a prompt
In this section, you will write a vague prompt for Bob, and review the output. You will then refine your prompt based on the best practices to improve the quality of the response.
The goal is to have Bob generate a Python function that prints the current date and time in UTC format. The function should be well documented and include error handling.
If the chat interface is closed, open it by clicking the Bob icon beside the navigation bar or use the shortcut Option + Command + B (Mac) or Ctrl + Alt + B (Windows).

Select Ask from the mode selector in the chat interface.
Enter the following prompt:
Write a Python function that prints the date and time.Bob will generate a response, but it may not meet all of your requirements.
from datetime import datetime
def print_datetime():
now = datetime.now()
print(now.strftime("%Y-%m-%d %H:%M:%S"))Bob generated a function, but it likely does not include error handling or is in a format other than UTC.
Start a new chat to clear the context window.
Now, refine your prompt to give Bob a role and include more specific instructions, examples, and context.
-
Add a role: Give Bob a role to help it understand the perspective it should take when generating the response. For example, "You are a senior software engineer with expertise in Python."
-
Add specific instructions: Be clear about what you want. For example, "Write a Python 3 function that prints the current date and time in UTC format."
-
Add context: Provide any additional information that can help Bob generate a better response. For example, "The function should be well documented and include error handling."
-
Example: Include an example of what you want the output to look like. If you have examples in your codebase, you can reference them using Bob @ context mentions, or link to external examples like documentation or authoritative sources like Real Python.
You are a senior software engineer with expertise in Python 3. Write a Python 3 function that prints the current date and time in UTC format. The function should be well documented and include error handling, modeled after https://realpython.com/ref/best-practices/exception-handling/."""
utc_datetime.py — Utility for printing the current UTC date and time.
"""
from datetime import datetime, timezone
def print_utc_datetime() -> None:
"""Print the current date and time in UTC (ISO 8601 format).
Retrieves the current moment from the system clock, attaches UTC timezone
info, formats it as an ISO 8601 string, and writes it to stdout.
Returns:
None
Raises:
OSError: If the system clock cannot be read (e.g., hardware failure or
OS-level permission restrictions).
ValueError: If datetime formatting unexpectedly fails (e.g., year out
of the supported range).
Example:
>>> print_utc_datetime()
Current UTC date and time: 2025-07-15T13:42:00.123456+00:00
"""
try:
now_utc: datetime = datetime.now(tz=timezone.utc)
except OSError as exc:
# System clock is unavailable or inaccessible.
raise OSError("Failed to read the system clock.") from exc
try:
formatted: str = now_utc.isoformat()
except ValueError as exc:
# Extremely unlikely, but guard against out-of-range datetime values.
raise ValueError(
f"Failed to format the datetime object: {now_utc!r}"
) from exc
print(f"Current UTC date and time: {formatted}")
if __name__ == "__main__":
print_utc_datetime()Bob's response should now be more aligned with your requirements, demonstrating the importance of writing effective prompts.
IBM SkillsBuild
IBM SkillsBuild is a free online learning platform that offers courses and resources to help you develop your skills in various technology domains, including AI and machine learning. You can find courses on how to write effective prompts for AI assistants like Bob, as well as other topics related to software development and technology.
To learn more about good prompt writing, take the Craft Precise Prompts for AI Models course.
Generate secure code with an actor-critic workflow
Use IBM Bob to configure security rules and apply an actor-critic pattern to generate Python code that satisfies security frameworks before it reaches a static analysis tool.
Tools
Learn how Bob uses specialized tools to read files, edit code, run commands, spawn subagents, use MCP integrations, and switch modes to streamline your coding workflow.