# Query Multiple Documents

### Overview

This procedure processes multiple documents with a custom prompt by uploading them directly to the LLM provider's file API (OpenAI Files API or Gemini Part). No OCR or image conversion is performed - the documents are sent as-is to the LLM for processing. This is efficient for handling multiple documents in a single API call.

{% hint style="warning" %}
Make sure to add the **Document Processing Book** to your agent before using this automation procedure.
{% endhint %}

{% hint style="info" %}
This procedure uploads PDF files directly to the LLM provider without OCR processing. It does not support scanned documents. Documents are processed in their native format using the LLM's file upload capabilities.
{% endhint %}

### Syntax

Below is a line-by-line overview of the automation syntax. Expand each line to learn more.

<details>

<summary><code>query the documents</code></summary>

#### What does it do?

Begins the request to process multiple documents with a custom prompt.

#### Where does it go?

This phrase should be written on a **new line**.

#### Is it required?

✅ Yes — This phrase is **required**.

#### Does it require data?

❌ No — This phrase does not require data.

#### Example

```
query the documents
```

</details>

<details>

<summary><code>the query is "your-query"</code></summary>

#### What does it do?

Specifies the custom query/prompt to use for processing the documents.

#### Where does it go?

Indented under `query the documents where`.

#### Is it required?

✅ Yes — This phrase is **required**.

#### Does it require data?

✅ Yes — Replace **your-query** with your custom instruction for the LLM.

#### Example

```
the query is "Extract all invoice numbers and dates from these documents"
```

</details>

<details>

<summary><code>the response format is "response-format"</code></summary>

#### What does it do?

Specifies the desired format of the response.

#### Where does it go?

Indented under `query the documents where`.

#### Is it required?

❌ No — This phrase is **optional**.

#### Does it require data?

✅ Yes — Replace **response-format** with one of the following: **string**, **text**, **table**, **list of texts**, **list of tables**, **structured data**, **json**. The default is **string**.

#### Example

```
the response format is "json"
```

</details>

<details>

<summary><code>the openai model is "openai-model"</code></summary>

#### What does it do?

Specifies the OpenAI model to use.

#### Where does it go?

Indented under `query the documents where`.

#### Is it required?

❌ No — This phrase is **optional**.

#### Does it require data?

✅ Yes — Replace **openai-model** with the name of an OpenAI model to use. The default is `gpt-4o`.

#### Example

```
the openai model is "gpt-4o"
```

</details>

<details>

<summary><code>the gemini model is "gemini-model"</code></summary>

#### What does it do?

Specifies the Gemini model to use.

#### Where does it go?

Indented under `query the documents where`.

#### Is it required?

❌ No — This phrase is **optional**.

#### Does it require data?

✅ Yes — Replace **gemini-model** with the name of the Gemini model to use. The default is `gemini-2.5-pro`.

#### Example

```
the gemini model is "gemini-2.0-flash"
```

</details>

### Examples

#### 1. Extract Invoice Information from Multiple Documents

```
the documents are the invoice files
query the documents where
    the query is "Extract invoice number, date, and total amount from each document. Return as JSON with keys: invoice_number, invoice_date, total_amount"
    the openai model is "gpt-4o"
```

#### 2. Summarize Multiple Reports

```
the documents are the reports
query the documents where
    the query is "Provide a brief summary of each document highlighting key findings and recommendations"
    the gemini model is "gemini-2.0-flash"
```

#### 3. Compare Multiple Contracts

```
the documents are the contracts
query the documents where
    the query is "Compare these contracts and identify key differences in terms, pricing, and obligations"
```
