> For the complete documentation index, see [llms.txt](https://docs.csml.dev/studio/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.csml.dev/studio/getting-started/using-csml-apps/preprocessing.md).

# Preprocessing

CSML Studio also offers a way to preprocess every incoming event of certain types, in order to add some metadata or transform it. Here are some use cases:

* transcribe audio inputs
* translate incoming text
* save uploaded files to a dedicated file storage
* perform OCR on each uploaded image
* run a custom natural language processing library on text inputs (for that use case, you may also want to look at [Natural Language Processing](/studio/getting-started/nlp.md))

Preprocessors are simply external apps that are run on every incoming event (of the given type) and return a valid CSML event. The only specificity is that the parameters it must accept and return are standard CSML event payloads. Preprocessors that fail to accept or return such payloads are simply ignored and your incoming event will not be transformed.

## How to add a CSML preprocessor

Let's create a simple Text preprocessor that will return a picture of a hot dog if the user had the word "hot dog" in their input, or change the text to `"Not hot dog"`  otherwise.

To add a preprocessor, you first need to add a *preprocessor-compatible* app under the apps section (see here). For this tutorial, let's just use the Quick Mode, but of course you can use Complete Mode as well.

This is the code we are going to use:

```javascript
exports.handler = async (event) => {

  const text = event.content.text;

  if (text.toLowerCase().includes('hot dog')) {
    return {
      content_type: 'image',
      content: {
P        url: 'https://media.istockphoto.com/photos/hot-dog-on-white-picture-id1130731707',
        _original_event: event,
      },
    };
  }

  return {
    content_type: 'text',
    content: {
      text: 'Not hot dog!',
      _original_event: event,
    },
  };

};

```

It is really simple: if the user text input contains the words "hot dog" anywhere, then return an image of a hotdog. Otherwise, change the text to "Not hot dog". In both cases, the original, untransformed event is still accessible with `event._original_event` in you CSML code, if needed.

Next, go to **Apps > Add Custom App** and under **Quick Mode**, simply copy and paste it, select a name for your app (for instance, `hotdog` seems like a fitting name), and click save.

![](/files/-MFKWFQ2wVA3fchnwbOv)

Then, head to the **Preprocessing** page. We only want to preprocess text events, but of course, we could do a similar app for other types of events.&#x20;

![](/files/-MbL_HlAYSbqFBkTwHlZ)

Now, back to the CSML Editor, you can do something like the following:

```cpp
start:
  if (event.get_type() == "image") say Image(event)
  else say event
  goto end
```

![](/files/-MbLaEvuuGSWdt2usJfS)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.csml.dev/studio/getting-started/using-csml-apps/preprocessing.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
