# Content Rules

By default, Medis attempts to select the most suitable encoder and viewer based on the content of the key. However, in certain scenarios, this automatic detection may fail. Additionally, the automatic detection does not take custom encoders into consideration, primarily due to performance constraints.

To address these limitations, Medis allows users to configure explicit content rules for encoders and viewers, based on the key name or type. This enables users to customize the encoding and decoding process, ensuring that the appropriate encoder and viewer are used for each key.

## Create a New Rule

To create a new rule, open the connection config modal and select the content rules tab.

![](/files/QmFsZbAWtzkoQEjESq4m)

Click the + button to create a new rule.

![](/files/gW7OlAbn0fmhts2GK8Ni)

#### When

There are two conditions, and only when the two conditions are satisfied at the same time, the preferred viewer and encoder will apply. If the key name pattern is left empty, all key names pass the condition.

The key name pattern supports glob rules like `*` and `?`.

#### Then

You can set either viewer or encoder or both of them. "Auto" is Medis's default behavior. For Hash/List/Set/Sorted Set keys, the viewer/encoder will be applied to their fields.


---

# Agent Instructions: 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:

```
GET https://docs.getmedis.com/settings/content-rules.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
