Custom Code
Execute custom JavaScript and Python code within your Prisme.ai workflows
The Custom Code app is a powerful infrastructure component in the Prisme.ai ecosystem that allows you to execute custom logic within your automations and workflows. It provides a secure, managed environment for running JavaScript and Python code, enabling complex data transformations, integrations, and calculations that go beyond what’s possible with standard automation steps.
Overview
Custom Code serves as a flexible extension point for your Prisme.ai solutions:
Code Execution
Run custom JavaScript and Python code in a secure environment
Data Transformation
Transform data with complex logic and algorithms
Integration Bridge
Connect to systems without pre-built integrations
Advanced Processing
Implement sophisticated data processing and analytics
This infrastructure app is particularly valuable for handling unique business logic, specialized calculations, and custom data processing requirements.
Key Features
A secure, controlled environment for running code:
- JavaScript Runtime: Execute JavaScript/TypeScript
- Python Runtime: Run Python 3.x code
- Isolation: Code runs in a containerized environment
- Resource Limits: CPU, memory, and execution time controls
- Version Management: Control runtime versions
This execution environment balances flexibility with security and stability.
A secure, controlled environment for running code:
- JavaScript Runtime: Execute JavaScript/TypeScript
- Python Runtime: Run Python 3.x code
- Isolation: Code runs in a containerized environment
- Resource Limits: CPU, memory, and execution time controls
- Version Management: Control runtime versions
This execution environment balances flexibility with security and stability.
Organize and manage custom functions:
- Function Library: Central repository of reusable functions
- Version Control: Track changes to functions over time
- Parameter Definition: Define and validate input parameters
- Default Values: Set fallback values for optional parameters
- Documentation: Document function purpose and usage
These management features promote code reuse and maintainability.
Connect code with the broader Prisme.ai ecosystem:
- Workflow Integration: Call functions from automations
- Data Passing: Exchange data between functions and workflows
- Context Access: Access runtime context information
- Error Handling: Robust error management
- Logging: Capture execution details for monitoring
These integration capabilities create a seamless experience within your workflows.
Tools to support code development and testing:
- Code Editor: Syntax highlighting and assistance
- Testing Framework: Validate function behavior
- Debugging Tools: Identify and resolve issues
- Execution History: Review past runs and outputs
- Performance Metrics: Monitor execution efficiency
These development tools improve productivity and code quality.
How Custom Code Works
Custom Code functions are defined, managed, and executed through a structured process:
Function Definition
Create a function with code, parameters, and metadata:
- Write the function code
- Define input parameters with types and validation
- Specify output format
- Add documentation
Storage and Management
Store functions in the Custom Code repository:
- Save to the function library
- Version and track changes
- Organize by category or purpose
- Control access permissions
Execution from Workflows
Call functions from automations:
- Reference the function by name
- Provide required parameters
- Map workflow data to parameters
- Capture the function output
Runtime Execution
Execute the function in a secure environment:
- Validate input parameters
- Run the code in an isolated container
- Monitor execution and resource usage
- Handle errors and exceptions
Result Processing
Return the result to the calling workflow:
- Format the output according to specifications
- Pass the result back to the workflow
- Log execution details
- Track performance metrics
This process provides a controlled yet flexible way to include custom logic in your automations.
JavaScript Functions
JavaScript functions in Custom Code allow you to implement a wide range of data processing and transformation tasks:
Python Functions
Python functions in Custom Code provide access to Python’s rich ecosystem for data analysis, machine learning, and scientific computing:
Integration with Prisme.ai Workflows
Custom Code is designed to integrate seamlessly with Prisme.ai automations:
Calling Functions from Automations
Reference Custom Code functions in your automation YAML:
This automation calls the processData
function with input from the payload and emits the result as an event.
Handling Function Results
Process the output from Custom Code functions:
This example shows conditional logic based on the function’s output.
Error Handling
Implement robust error handling for Custom Code execution:
This approach captures and logs errors from function execution.
Common Use Cases
Custom Code enables a wide range of use cases:
Data Transformation
Implement complex data transformations:
- Format conversion
- Schema mapping
- Data normalization
- Content extraction
Advanced Analysis
Perform sophisticated data analysis:
- Statistical calculations
- Pattern recognition
- Trend identification
- Risk assessment
Integration Logic
Create custom integration components:
- API request formatting
- Response processing
- Protocol implementations
- Legacy system connections
Business Logic
Implement specialized business rules:
- Pricing calculations
- Eligibility determinations
- Approval workflows
- Validation logic
Example: Data Classification
A common use case for Custom Code is classifying data based on content. Here’s an example that classifies documents:
This function analyzes document content, scoring it against different category patterns, and assigns the most likely classification if it meets a minimum confidence threshold.
Example: Advanced Data Analysis with Python
When you need sophisticated data analysis, Python’s ecosystem provides powerful capabilities:
This Python function uses the Isolation Forest algorithm to detect anomalous transactions based on multiple features, providing detailed information about the detected anomalies.
Best Practices
Follow these recommendations to get the most from Custom Code:
Limitations and Considerations
When using Custom Code, be aware of these considerations:
-
Execution Environment: Code runs in a controlled environment with resource limits. Very compute-intensive operations may not be suitable.
-
External Access: For security reasons, network access is restricted. External API calls and file system access follow platform security policies.
-
Runtime Duration: Functions have maximum execution times. Long-running operations should be designed with this in mind.
-
Library Availability: While many common libraries are available, some specialized packages may not be pre-installed. Check documentation for the current list.
-
State Management: Functions are stateless by default. Persistent state should be stored using platform services like Collection.
Integration with Other Prisme.ai Products
Custom Code works seamlessly with other Prisme.ai products:
Enhance AI Knowledge with custom processing:
- Pre-process documents before ingestion
- Create custom embedding algorithms
- Implement specialized reranking logic
- Generate synthetic training data
- Analyze query patterns and performance
This integration improves retrieval accuracy and knowledge base utility.
Enhance AI Knowledge with custom processing:
- Pre-process documents before ingestion
- Create custom embedding algorithms
- Implement specialized reranking logic
- Generate synthetic training data
- Analyze query patterns and performance
This integration improves retrieval accuracy and knowledge base utility.
Extend automation capabilities with custom logic:
- Implement complex workflow decisions
- Create custom integration points
- Build specialized data transformations
- Generate dynamic content
- Process and analyze event data
This combination enables sophisticated automation scenarios.
Enhance web content extraction with custom processing:
- Implement specialized content extraction
- Clean and normalize crawled data
- Filter and categorize content
- Extract structured data from HTML
- Transform content into specific formats
This integration improves the quality and usability of extracted web content.
Add sophisticated data operations for Collection:
- Implement custom querying logic
- Create specialized aggregations
- Build data migration tools
- Generate data quality reports
- Perform batch processing operations
This combination enhances data management capabilities.
Next Steps
Was this page helpful?