Actions allow you to deploy serverless Python functions that can be triggered on-demand by endpoints or used as tools by AI agents. Think of actions as lambda-like functions that run in isolated environments.
Copy
from datazone.actions import action@actiondef send_email(to: str, subject: str, body: str): """ Send an email to a recipient. """ # Your email sending logic here print(f"Sending email to {to}") # Return structured result return { "status": "sent", "recipient": to, "timestamp": "2026-02-11T10:00:00Z" }
Actions are custom Python functions that run in isolated environments, accept parameters, return structured results, and can be triggered via endpoints or used as agent tools.
Access workspace variables securely within actions.
Copy
# Access a variableapi_key = Variable("API_KEY")# Convert to string for useapi_key_str = str(api_key)# Use in your action logicheaders = {"Authorization": f"Bearer {str(Variable('AUTH_TOKEN'))}"}
Variables are workspace-scoped and can be marked as secret to encrypt sensitive data like API keys, passwords, and tokens.Learn more in the Variables documentation.
from datazone.actions import action, Variable@actiondef send_notification(message: str): """Send notification using API key from Variables.""" # Access API key stored as Variable api_key = str(Variable("API_KEY")) # Use the API key print(f"Sending notification with key: {api_key[:4]}...") return {"status": "sent", "message": message}
Security Best Practice: Always store sensitive credentials as Variables rather than hardcoding them in your action code.
Actions can raise exceptions - they’ll be captured and returned:
Copy
@actiondef validate_input(value: int): """Validate input value.""" if value < 0: raise ValueError("Value must be positive") return {"validated": True, "value": value}
from datazone.actions import action, context@actiondef validate_customer_data(customer_id: str, email: str, age: int): """ Validate customer data before processing. Args: customer_id: Customer identifier email: Customer email address age: Customer age """ errors = [] # Validate email if "@" not in email: errors.append("Invalid email format") # Validate age if age < 18 or age > 120: errors.append("Age must be between 18 and 120") if errors: context.log_error(f"Validation failed: {', '.join(errors)}") return { "valid": False, "errors": errors } context.log_info("Validation passed") return { "valid": True, "customer_id": customer_id }