Skip to main content

Langfuse Integration

Note: Control Zero handles policy enforcement. Langfuse is a complementary observability tool. For tracing and evaluation, these tools work alongside Control Zero.

Use Control Zero for policy enforcement alongside Langfuse for tracing.

Overview​

Control Zero and Langfuse solve different problems and work well together:

  • Control Zero: Enforces governance policies (what agents are allowed to do)
  • Langfuse: Provides observability and tracing (what agents actually did)

Together, they give you both prevention (block unauthorized actions) and visibility (trace and debug all actions).

Installation​

pip install controlzero langfuse openai

Combined Setup​

from controlzero import Client
from langfuse import Langfuse
from langfuse.openai import openai # Langfuse-wrapped OpenAI client

# [Control Zero: policy enforcement]
cz = Client(api_key="cz_live_your_api_key_here")

# [Langfuse: observability]
langfuse = Langfuse(
public_key="pk-...",
secret_key="sk-...",
host="https://cloud.langfuse.com",
)

Usage Pattern​

Enforce policies with Control Zero, then let Langfuse trace the execution:

from langfuse.decorators import observe

@observe()
def generate_response(prompt: str, agent_id: str) -> str:
"""Generate a response with both enforcement and tracing."""

# Step 1: Control Zero enforces the policy
cz.guard("llm", method="generate", args={"model": "gpt-5.4", "agent_id": agent_id})

# Step 2: Langfuse traces the call (via its OpenAI wrapper)
response = openai.chat.completions.create(
model="gpt-5.4",
messages=[{"role": "user", "content": prompt}],
)

return response.choices[0].message.content


@observe()
def handle_tool_call(tool_name: str, arguments: dict, agent_id: str) -> str:
"""Execute a tool call with enforcement and tracing."""

# Enforce before execution
cz.guard(tool_name, args={"agent_id": agent_id})

# Tool execution is automatically traced by Langfuse
result = execute_tool(tool_name, arguments)
return result

What Each Tool Provides​

CapabilityControl ZeroLangfuse
Block unauthorized actionsYesNo
Allow/deny policiesYesNo
Encrypted policy bundlesYesNo
LLM call tracingNo (logs decisions only)Yes
Cost trackingNoYes
Prompt managementNoYes
Latency monitoringNoYes
Evaluation scoresNoYes

Next Steps​

  • See the Python SDK for the full Control Zero API reference.
  • Learn about Policies for defining governance rules.