Before running your application, ensure you have the following environment variables set:
export ARIZE_SPACE_ID="YOUR_ARIZE_SPACE_ID"export ARIZE_API_KEY="YOUR_ARIZE_API_KEY"export OPENAI_API_KEY="YOUR_OPENAI_API_KEY" # Needed for the example code# Add other LLM provider API keys if used by Guardrails
Sign up for a free Arize AX account. You can find your Arize Space ID and API Key in your Arize AX account settings.
Now you can run your Guardrails AI code as usual. The instrumentor will capture relevant trace data.
# Ensure OPENAI_API_KEY is set in your environment for this exampleimport openaifrom guardrails import Guardfrom guardrails.hub import TwoWords # Example validator# Initialize Guardrailsguard = Guard().use( TwoWords() # Using a simple validator from the hub)# Make a call through Guardrails# This will also make an underlying call to the OpenAI LLMresponse = guard( llm_api=openai.chat.completions.create, prompt="What is another name for America?", model="gpt-3.5-turbo", max_tokens=1024, # You can add instructions or other parameters as needed by your spec)# Print the validated (or processed) responseif response.validation_passed: print(f"Validated Output: {response.validated_output}")else: print(f"Validation Failed. Raw LLM Output: {response.raw_llm_output}") print(f"Validation Details: {response.validation_details}")