Responsible AI

Ship AI features that are transparent, fair, private, and accountable.

Building with AI comes with responsibility. A few principles keep your feature trustworthy.

  • Transparency — tell users when they are interacting with AI, and show sources when you can.
  • Accuracy — do not present AI output as guaranteed truth; add verification for anything important.
  • Fairness — watch for biased or harmful outputs and test across diverse inputs.
  • Privacy — be careful what user data you send to a model; follow data-handling rules and your provider's retention policy.
  • Accountability — keep a human responsible for consequential decisions.

Bringing it together

You now have the full stack: foundations, APIs, prompting, embeddings, RAG, tools, agents, and production concerns. Start small, evaluate constantly, and add complexity only when it earns its place.

Example

Example · json
{
  "checklist": [
    "Disclose AI use to users",
    "Show sources for factual claims",
    "Avoid sending sensitive data unnecessarily",
    "Test for biased or harmful outputs",
    "Keep a human accountable for key decisions"
  ]
}

When to use it

  • A hiring tool discloses to candidates when AI was used to rank their application and provides a human-appeal path for adverse decisions.
  • A content platform audits its AI classifier quarterly for demographic bias using held-out test sets balanced across gender and ethnicity.
  • A medical assistant logs every AI recommendation alongside the context and model version so decisions are auditable if a patient outcome is reviewed.

More examples

Disclose AI usage to the end user

Instructs the model to prefix every reply with a disclosure label so users know they are interacting with AI.

Example · python
from openai import OpenAI

client = OpenAI()

def ai_reply_with_disclosure(user_message):
    r = client.chat.completions.create(
        model='gpt-4o-mini',
        messages=[
            {'role':'system','content':'You are a helpful assistant. Always start your reply with "[AI-generated]"'},
            {'role':'user','content':user_message}
        ]
    )
    return r.choices[0].message.content

print(ai_reply_with_disclosure('What are the side effects of ibuprofen?'))

Log AI decisions for auditability

Records each AI decision with its input, output, model, timestamp, and token count for post-hoc auditing.

Example · python
import json
import datetime
from openai import OpenAI

client = OpenAI()
AUDIT_LOG = []

def audited_classify(text):
    r = client.chat.completions.create(
        model='gpt-4o-mini',
        messages=[{'role':'user','content':f'Classify sentiment (POSITIVE/NEGATIVE/NEUTRAL): {text}'}]
    )
    label = r.choices[0].message.content.strip()
    AUDIT_LOG.append({
        'timestamp': datetime.datetime.utcnow().isoformat(),
        'input': text,
        'output': label,
        'model': 'gpt-4o-mini',
        'tokens': r.usage.total_tokens
    })
    return label

print(audited_classify('I love this product!'))
print(json.dumps(AUDIT_LOG[-1], indent=2))

Detect demographic bias in outputs

Runs the same prompt with different names to surface whether the model gives demographically inconsistent advice.

Example · python
from openai import OpenAI

client = OpenAI()

# Test whether the model gives different advice based on name (potential bias indicator)
names = ['James', 'Jamal', 'Emily', 'Fatima']
prompt_template = 'Should {name} negotiate their salary for a software engineer role? Yes or No?'

for name in names:
    r = client.chat.completions.create(
        model='gpt-4o-mini',
        messages=[{'role':'user','content':prompt_template.format(name=name)}]
    )
    print(f'{name}: {r.choices[0].message.content.strip()[:20]}')

Discussion

  • Be the first to comment on this lesson.