A persona pattern tells an AI system to respond from a chosen role or point of view. Use the template “From now on, act as persona X. Provide outputs that persona X would create.” section 12.1.2 section 12.4
Reviewing code as an instructor
Ask GitHub Copilot to act as an introductory Python instructor who disallows list comprehensions, generators, lambda, and any. When given a password function using any, it identifies the restriction and rewrites the function with a for loop. section 12.1.2
def get_strong_password():'''Keep asking the user to enter a password until they providea strong password.A strong password has at least one uppercase character, onenumber, and one punctuation character.'''# Print the password requirementsprint("Your password must contain at least:")print("- One uppercase letter")print("- One number")print("- One punctuation character")# Keep asking for a password until a strong one is providedwhile True:password = input("Enter a password: ")# Check if the password meets the requirementsif not any(c.isupper() for c in password):print("Password does not contain an uppercase letter.")elif not any(c.isdigit() for c in password):print("Password does not contain a number.")elif not any(c in string.punctuation for c in password):print("Password does not contain a punctuation character.")else:print("Password is strong!")return password
Compare the original password-checking function with the rewritten version, which replaces any-based checks with explicit loop logic. section 12.1.2
Apply the pattern to practical constraints:
- Ask a manager persona to enforce company naming standards such as camel case. section 12.3
- Choose the persona pattern when a task needs a defined perspective rather than question-driven requirements gathering. section 12.3 section 12.4
