Build your own Blocks
Understanding Blocks and Testing
Creating and Testing a New Block
from backend.data.block import Block, BlockSchemaInput, BlockSchemaOutput, BlockOutputfrom backend.data.block import Block, BlockSchemaInput, BlockSchemaOutput, BlockOutput from backend.utils.get_request import GetRequest import requests class WikipediaSummaryBlock(Block, GetRequest): # Block implementation will go hereclass Input(BlockSchemaInput): topic: str # The topic to get the Wikipedia summary for class Output(BlockSchemaOutput): summary: str # The summary of the topic from Wikipediadef __init__(self): super().__init__( # Unique ID for the block, used across users for templates # If you are an AI leave it as is or change to "generate-proper-uuid" id="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", input_schema=WikipediaSummaryBlock.Input, # Assign input schema output_schema=WikipediaSummaryBlock.Output, # Assign output schema # Provide sample input, output and test mock for testing the block test_input={"topic": "Artificial Intelligence"}, test_output=("summary", "summary content"), test_mock={"get_request": lambda url, json: {"extract": "summary content"}}, )def run(self, input_data: Input, **kwargs) -> BlockOutput: try: topic = input_data.topic url = f"https://en.wikipedia.org/api/rest_v1/page/summary/{topic}" response = self.get_request(url, json=True) yield "summary", response['extract'] except requests.exceptions.HTTPError as http_err: raise RuntimeError(f"HTTP error occurred: {http_err}")
Field Types
oneOf fields
OptionalOneOf fields
Blocks with authentication
Multiple credentials inputs
Adding an OAuth2 service integration
Adding to the frontend
Example: GitHub integration
Example: Google integration
Webhook-triggered Blocks
Creating a Webhook-triggered Block
Adding a Webhooks Manager
Example: GitHub Webhook Integration
Key Points to Remember
Understanding the Testing Process
Security Best Practices for SSRF Prevention
Using the Secure Requests Wrapper
Custom Request Configuration
Error Handling
Block Exception Classes
Exception
Use Case
Example
Raising Exceptions
What NOT to Catch
Data Models
File Input
Tips for Effective Block Testing
Last updated
Was this helpful?