Prompt engineering deliberately designs and refines messages sent to a language model so responses become more effective and consistent. It combines clear instructions, relevant context, iteration, and evaluation rather than relying on a single perfect request. section 1.3 section 2.3
A practical prompt-engineering workflow includes:
- Write clear, specific instructions with the information and context relevant to the task. section 2.3
- Iterate after inspecting the response; refine the request or add a system prompt when the result is weak. section 9.1
- Test changes systematically by comparing prompt or profile variants and scoring them against a rubric. section 9.8
- Extend prompting toward reasoning and planning when the task involves difficult problems or ordered actions. section 10.0 section 10.2
From vague request to useful recommendation
Replace “can you recommend something” with “Can you please recommend a time travel movie set in the medieval period.” Adding a system prompt such as “You are an expert on time travel movies” further establishes the response role. The same refinement pattern can be tested interactively in ChatGPT or through a Python prompt tester. section 9.1 section 2.3
Listing 2.8 prompt_engineering.py (main())
def main():
directory = "prompts"
text_files = list_text_files_in_directory(directory) #1
if not text_files:
print("No text files found in the directory.")
return
def print_available(): #2
print("Available prompt tactics:")
for i, filename in enumerate(text_files, start=1):
print(f"{i}. {filename}")
while True:
try:
print_available() #2
choice = int(input("Enter … 0 to exit): ")) #3
if choice == 0:
break
elif 1 <= choice <= len(text_files):
selected_file = text_files[choice - 1]
file_path = os.path.join(directory,
selected_file)
prompts =
load_and_parse_json_file(file_path) #4
print(f"Running prompts for {selected_file}")
for i, prompt in enumerate(prompts):
print(f"PROMPT {i+1} --------------------")
print(prompt)
print(f"REPLY ---------------------------")
print(prompt_llm(prompt)) #5
else:
print("Invalid choice. Please enter a valid number.")
except ValueError:
print("Invalid input. Please enter a number.")
Use the prompt_engineering.py listing to follow a runnable workflow that loads prompt files, lets users select tactics, submits prompts to an LLM, and prints responses. section 2.3





































