> ## Documentation Index
> Fetch the complete documentation index at: https://www.getmaxim.ai/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# QueryBuilder

> Query_Builder utilities for data models and type definitions used throughout the maxim sdk.

[View module source on GitHub](https://github.com/maximhq/maxim-py/blob/main/maxim/models/query_builder.py)

## [QueryBuilder](/sdk/python/references/models/query_builder)

```python theme={null}
class QueryBuilder()
```

This class represents a query builder. Users can use this class to build a query rule for fetching prompts, agents or workflow from [Maxim](/sdk/python/references/maxim) server.

#### and\_

```python theme={null}
def and_() -> 'QueryBuilder'
```

Sets the operator for combining query rules to 'AND'.

**Returns**:

| Name                                                          | Description                                            |
| ------------------------------------------------------------- | ------------------------------------------------------ |
| `[QueryBuilder](/sdk/python/references/models/query_builder)` | The current QueryBuilder instance for method chaining. |

#### or\_

```python theme={null}
def or_() -> 'QueryBuilder'
```

Sets the operator for combining query rules to 'OR'.

**Returns**:

| Name                                                          | Description                                            |
| ------------------------------------------------------------- | ------------------------------------------------------ |
| `[QueryBuilder](/sdk/python/references/models/query_builder)` | The current QueryBuilder instance for method chaining. |

#### folder

```python theme={null}
def folder(folderId: str) -> 'QueryBuilder'
```

Sets the folder scope for the query.

**Arguments**:

| Name       | Type  | Description                               |
| ---------- | ----- | ----------------------------------------- |
| `folderId` | *str* | The ID of the folder to set as the scope. |

**Returns**:

| Name                                                          | Description                                            |
| ------------------------------------------------------------- | ------------------------------------------------------ |
| `[QueryBuilder](/sdk/python/references/models/query_builder)` | The current QueryBuilder instance for method chaining. |

#### exact\_match

```python theme={null}
def exact_match() -> 'QueryBuilder'
```

Sets the exact match flag to True.

**Returns**:

| Name                                                          | Description                                            |
| ------------------------------------------------------------- | ------------------------------------------------------ |
| `[QueryBuilder](/sdk/python/references/models/query_builder)` | The current QueryBuilder instance for method chaining. |

#### deployment\_var

```python theme={null}
def deployment_var(key: str,
                   value: Union[str, int, bool],
                   enforce: bool = True) -> 'QueryBuilder'
```

Adds a deployment variable rule to the query.

**Arguments**:

| Name      | Type                     | Description                                                   |
| --------- | ------------------------ | ------------------------------------------------------------- |
| `key`     | *str*                    | The key of the deployment variable.                           |
| `value`   | *Union\[str, int, bool]* | The value of the deployment variable.                         |
| `enforce` | *bool, optional*         | Whether to enforce the deployment variable. Defaults to True. |

**Returns**:

| Name                                                          | Description                                            |
| ------------------------------------------------------------- | ------------------------------------------------------ |
| `[QueryBuilder](/sdk/python/references/models/query_builder)` | The current QueryBuilder instance for method chaining. |

#### tag

```python theme={null}
def tag(key: str,
        value: Union[str, int, bool],
        enforce: bool = False) -> 'QueryBuilder'
```

Adds a tag rule to the query.

**Arguments**:

| Name      | Type                     | Description                                    |
| --------- | ------------------------ | ---------------------------------------------- |
| `key`     | *str*                    | The key of the tag.                            |
| `value`   | *Union\[str, int, bool]* | The value of the tag.                          |
| `enforce` | *bool, optional*         | Whether to enforce the tag. Defaults to False. |

**Returns**:

| Name                                                          | Description                                            |
| ------------------------------------------------------------- | ------------------------------------------------------ |
| `[QueryBuilder](/sdk/python/references/models/query_builder)` | The current QueryBuilder instance for method chaining. |

#### build

```python theme={null}
def build() -> QueryRule
```

Builds the final query rule.

**Raises**:

* `ValueError` - If the query is empty after trimming.

**Returns**:

| Name        | Description                                |
| ----------- | ------------------------------------------ |
| `QueryRule` | A QueryRule instance with the built query. |
