Skip to main content
# pip install "upsonic[safety-engine]"
uv pip install "upsonic[safety-engine]"

What is Medical Info Policy?

Medical information policies detect and protect health records, diagnoses, prescriptions, medical IDs, insurance information, and other Protected Health Information (PHI) for HIPAA compliance.

Why its Important?

Medical information policies are crucial for ensuring HIPAA compliance and protecting patient privacy. These policies prevent Protected Health Information (PHI) from being sent to LLMs, which helps maintain compliance with healthcare regulations and protects sensitive medical data from unauthorized access.
  • Prevents sending PHI to LLM: Blocks medical records, diagnoses, prescriptions, and health insurance information from being processed by language models
  • Ensures HIPAA compliance: Helps maintain compliance with Health Insurance Portability and Accountability Act requirements, avoiding severe penalties
  • Protects patient privacy: Prevents sensitive medical information from being exposed to third-party LLM providers, protecting patient confidentiality

Anonymize (Unique Random Placeholders)

MedicalInfoAnonymizePolicy replaces detected medical data with unique random placeholders. Original values are restored in the agent’s response:
from upsonic import Agent, Task
from upsonic.safety_engine.policies import MedicalInfoAnonymizePolicy

agent = Agent(
    "anthropic/claude-sonnet-4-6",
    user_policy=MedicalInfoAnonymizePolicy,
    debug=True
)

task = Task("Patient John Doe has diabetes and takes metformin 500mg. Summarize the patient info.")
result = agent.print_do(task)
print(result)  # Medical terms are de-anonymized in the response

Replace (Fixed Placeholder)

MedicalInfoReplacePolicy replaces detected medical data with [MEDICAL_INFO_REDACTED]. All detected values share the same placeholder — original values are still restored in the final response:
from upsonic import Agent, Task
from upsonic.safety_engine.policies import MedicalInfoReplacePolicy

agent = Agent(
    "anthropic/claude-sonnet-4-6",
    user_policy=MedicalInfoReplacePolicy,
    debug=True
)

task = Task("Patient John Doe has diabetes and takes metformin 500mg.")
result = agent.print_do(task)
print(result)  # Medical info replaced with [MEDICAL_INFO_REDACTED]

Block

MedicalInfoBlockPolicy blocks any content containing medical information:
from upsonic import Agent, Task
from upsonic.safety_engine.policies import MedicalInfoBlockPolicy

agent = Agent(
    "anthropic/claude-sonnet-4-6",
    user_policy=MedicalInfoBlockPolicy,
    debug=True
)

result = agent.print_do(Task("Patient John Doe has diabetes. Explain the disease"))
print(result)

Streaming

Medical policies work with streaming — anonymized medical data is de-anonymized in real-time:
import asyncio
from upsonic import Agent, Task
from upsonic.safety_engine.policies import MedicalInfoAnonymizePolicy

async def main():
    agent = Agent(
        "anthropic/claude-sonnet-4-6",
        user_policy=MedicalInfoAnonymizePolicy,
        debug=True,
    )

    task = Task("Patient John Doe has diabetes and takes metformin. Summarize the patient info.")

    async for text in agent.astream(task):
        print(text, end="", flush=True)
    print()

asyncio.run(main())

Available Variants

  • MedicalInfoBlockPolicy: Pattern detection with blocking
  • MedicalInfoBlockPolicy_LLM: LLM-powered block messages
  • MedicalInfoBlockPolicy_LLM_Finder: LLM detection for better accuracy
  • MedicalInfoAnonymizePolicy: Anonymizes medical data with unique random replacements
  • MedicalInfoReplacePolicy: Replaces with [MEDICAL_INFO_REDACTED] (fixed placeholder)
  • MedicalInfoRaiseExceptionPolicy: Raises DisallowedOperation exception
  • MedicalInfoRaiseExceptionPolicy_LLM: LLM-generated exception messages