Last active
May 20, 2026 19:05
-
-
Save rshepherd/5b3c8ad24c5a4e2ca321c5b80fd332cf to your computer and use it in GitHub Desktop.
PII LLM Call
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| Create a key here" https://platform.openai.com/settings/organization/api-keys | |
| Setup: | |
| pip install openai | |
| Environment variable: | |
| export OPENAI_API_KEY="your_api_key" | |
| Use GPT-5 Mini, which would cost about ~$0.000085 per request | |
| """ | |
| from openai import OpenAI | |
| client = OpenAI() | |
| # ------------------------- | |
| # SYSTEM PROMPT | |
| # ------------------------- | |
| SYSTEM_PROMPT = """ | |
| You remove personally identifiable information (PII) from text. | |
| Replace: | |
| - Names with [PERSON] | |
| - Phone numbers with [PHONE] | |
| - Email addresses with [EMAIL] | |
| - Street addresses with [ADDRESS] | |
| Return only the cleaned text. | |
| """ | |
| # ------------------------- | |
| # USER INPUT | |
| # ------------------------- | |
| post = """ | |
| Had a great time at dinner with Sarah Johnson last night. | |
| Call me at 917-555-1234 or email me at randy@example.com. | |
| """ | |
| # ------------------------- | |
| # LLM CALL | |
| # ------------------------- | |
| response = client.responses.create( | |
| model="gpt-5-mini", | |
| input=[ | |
| { | |
| "role": "system", | |
| "content": SYSTEM_PROMPT, | |
| }, | |
| { | |
| "role": "user", | |
| "content": post, | |
| }, | |
| ], | |
| ) | |
| """ | |
| Expected output: | |
| Had a great time at dinner with [PERSON] last night. | |
| Call me at [PHONE] or email me at [EMAIL]. | |
| """ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment