Usage with OpenAI

Learn about usage of Spro with OpenAI.

This guide provides an overview of how to use Spro with OpenAI's large language models (LLMs) to ensure the secure handling of sensitive information. By integrating Spro with OpenAI, you can mask sensitive data before it reaches the language model, ensuring privacy and compliance with data protection regulations.

Using Spro with OpenAI

Spro acts as a secure gateway to privacy-compliant AI interactions, enabling you to interact with OpenAI's LLMs without disclosing sensitive information. By automatically detecting and masking sensitive data, Spro ensures that privacy and compliance standards are upheld. This specialized tool is designed to manage and protect sensitive information when used with large language models, allowing for effective communication while keeping confidential data secure.

from spro import Spro
from openai import OpenAI

# Initialize clients
client = OpenAI()
spro_client = Spro()

# Secure the prompt with Spro
masked_text = spro_client.secure(prompt="""
Compose an email to my Boss John Doe with my email address ok@example.com requesting a day off on friday.
""", mask_type="enhanced")["redacted_text"]

# Use the masked text with OpenAI's GPT-4o-mini model
stream = client.chat.completions.create(
    messages=[
        {
            "role": "user",
            "content": masked_text,
        }
    ],
    model="gpt-4o-mini",
    stream=True
)

# Print the response from the LLM
for chunk in stream:
    print(chunk.choices[0].delta.content or "", end="")

In the example above, we first secure the prompt using Spro's secure method with the mask_type parameter set to "enhanced". This ensures that sensitive information is masked before it is sent to OpenAI's GPT-4 model. The masked text is then used as the input to the LLM, and the response is printed to the console.

Sample model response:

Here's a sample email:

**Subject: Vacation Request for [DATE]**

**From:** [EMAIL](mailto:[EMAIL])
**To:** [PERSON]
**Date:** [Current Date]

Dear [PERSON],

I am writing to request some time off for a scheduled vacation. I am planning to be out of the office on **[DATE]** and I would like to ensure that my team is aware of my absence in advance.

I will make sure to complete all my tasks and ensure a smooth transition of work before I leave. If there are any concerns or if there's anything specific you would like me to focus on before my leave, please let me know.

Thank you for considering my request. I look forward to hearing back from you.

Best regards,
[Your Name]