> For the complete documentation index, see [llms.txt](https://platformdocs.lattica.ai/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://platformdocs.lattica.ai/how-to-guides/secure-query-processing/how-to-execute-query.md).

# How To: Execute Query

### Prerequisites

1. **Encrypted Message**:\
   The input [message must be encrypted ](/how-to-guides/secure-query-processing/how-to-encrypt-input-message.md)using the **Secret Key** in the Query Client.
2. **User Access Token**:\
   The user must have a valid **Access Token**, specific to the workload being queried. Tokens are validated by LatticaAI during the query process.

***

Use the following code snippet to execute the query. Provide the **User Access Token** and the **encrypted message** as parameters:

{% tabs %}
{% tab title="🧊Python SDK" %}

```python
import lattica_common.app_api as agent_app
​
# Notice your query token expires in 30 days
query_token = "the_query_token_you_got_using_the_generate_user_token"

# user_data is a tuple of: 
# (serialized_context, serialized_secret_key, serialized_homseq)
# which you need for encrypting the query and querying the model
user_data = agent_app.user.query_offline_phase(query_token)

dataset = pd.read_csv('data/mnist_data.csv').values / 255
data = torch.tensor(dataset[0])
serialized_ct = agent_app.user.encrypt(user_data, dataset)

serialized_ct_res = agent_app.user.apply_hom_pipeline(serialized_ct)
```

{% endtab %}

{% tab title="📦TypeScript SDK" %}

```javascript
import { LatticaQueryClient } from 'lattica-query-client';

const client = new LatticaQueryClient('your-jwt-query-token');

// Uploaded the EK
const initialized = await client.init();
if (!initialized) {
  console.error('Initialization failed: The EK was not successfully uploaded.');
  throw new Error('EK upload failed.');
}
console.log('EK uploaded successfully.');

// The data you want to encrypt
const inputTensor = ....;

// Encrypt the provided input
const ct = await client.encrypt(pt);

// Send your encrypted query to and get a resopnse
const ct_res = await latticaClient.apply_query(ct);
```

{% endtab %}
{% endtabs %}

**Process the Response**

* If the query is successful, the result will be returned as an **encrypted response**.
* [Decrypt ](/how-to-guides/secure-query-processing/how-to-decrypt-output-data.md)the response using your **Secret Key** to obtain the result.

{% hint style="info" %}
This step focuses on a specific part of the query process: Query Execution. \
If you prefer to perform **encryption, query execution, and decryption** in a single command, refer to \[How-To: [Encrypt, Execute, and Decrypt in One Step](/how-to-guides/secure-query-processing/how-to-encrypt-execute-and-decrypt-in-one-step.md)].
{% endhint %}


---

# 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://platformdocs.lattica.ai/how-to-guides/secure-query-processing/how-to-execute-query.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.
