Skip to content

Commit

Permalink
Add schema processing docs
Browse files Browse the repository at this point in the history
  • Loading branch information
kaavee315 committed Sep 19, 2024
1 parent df2fa0b commit bedb513
Showing 1 changed file with 24 additions and 12 deletions.
36 changes: 24 additions & 12 deletions docs/introduction/foundations/components/actions/processing.mdx
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
---
title: "🛠️ Enhancing Action Inputs & Outputs"
title: "🛠️ Enhancing Action Inputs, Outputs & Schemas"
sidebarTitle: "Processing Actions"
icon: "wand-magic-sparkles"
description: "Master the art of preprocessing and postprocessing actions for optimal results."
description: "Master the art of preprocessing, postprocessing, and schema processing for optimal results."
---

## Refining Action Inputs & Outputs
## Refining Action Inputs, Outputs & Schemas

In many scenarios, the raw inputs or outputs of actions may benefit from additional processing. This refinement step can significantly improve the quality and usability of your data. Here are two key use cases:
In many scenarios, the raw inputs, outputs, or schemas of actions may benefit from additional processing. This refinement step can significantly improve the quality and usability of your data. Here are three key use cases:

- **Postprocessing**: Streamline large action responses by filtering or formatting the data before it reaches the Language Model (LLM).
- **Preprocessing**: Generate or modify inputs dynamically at runtime, handling scenarios that may be challenging for the LLM to produce directly.
- **Postprocessing**: Streamline large action responses by filtering or formatting the data before it reaches the Language Model (LLM).
- **Schema Processing**: Modify the request schema to include additional fields or alter existing ones.

Composio empowers you with the ability to define **custom Python functions** as preprocessors or postprocessors.
Composio empowers you with the ability to define **custom Python functions** as preprocessors, postprocessors, or schema processors.

These can be applied at two levels:

Expand All @@ -21,9 +22,13 @@ These can be applied at two levels:

Here's how you can implement these processors:
<Steps>
<Step title="Define the Preprocessor or Postprocessor Functions">
<Step title="Define the Preprocessor, Postprocessor, and Schema Processor Functions">
<CodeGroup>
```python Define the Preprocessor or Postprocessor Functions
```python Define the Preprocessor, Postprocessor, and Schema Processor Functions
def tool_schema_processor(schema):
# Modify schema as needed
return modified_schema

def tool_preprocessor(input_data):
# Modify input_data as needed
return modified_input_data
Expand All @@ -32,6 +37,10 @@ def tool_postprocessor(output_data):
# Process output_data as needed
return processed_output_data

def action_schema_processor(schema):
# Modify schema as needed
return modified_schema

def action_preprocessor(input_data):
# Modify input_data as needed
return modified_input_data
Expand All @@ -44,10 +53,14 @@ def action_postprocessor(output_data):
</Step>
<Step title="Use them while creating the toolset">
<CodeGroup>
```python Set the pre and post processors while creating the toolset
# while defining the toolset, you can define the pre and post processors
```python Set the schema, pre, and post processors while creating the toolset
# While defining the toolset, you can define the schema, pre, and post processors
composio_toolset = ComposioToolSet(
processors={
"schema": {
App.GITHUB: tool_schema_processor,
Action.GITHUB_STAR_A_REPOSITORY_FOR_THE_AUTHENTICATED_USER: action_schema_processor,
},
"pre": {
App.GITHUB: tool_preprocessor,
Action.GITHUB_STAR_A_REPOSITORY_FOR_THE_AUTHENTICATED_USER: action_preprocessor,
Expand All @@ -65,7 +78,6 @@ tools = composio_toolset.get_tools(apps=[App.GITHUB])
</Step>
</Steps>


<Warning>
Ensure that your preprocessing and postprocessing functions are efficient and don't introduce significant latency.
Ensure that your schema processing, preprocessing, and postprocessing functions are efficient and don't introduce significant latency.
</Warning>

0 comments on commit bedb513

Please sign in to comment.