# Fetching a Prompt

The `fetch_prompt()` method retrieves stored prompts based on filters.

#### **Example Usage**

```python
def fetch_prompt(self, client_uuid, m=1, get_latest_version=False):
    prompt_id = client_uuid + ":" + str(m)
    query = {"prompt_id": prompt_id}
    
    results = self.mongodb_connection.read(collection_name="promptlake", query=query)

    if not results:
        return None if get_latest_version else []

    if get_latest_version:
        versions = [int(doc["prompt_version"]) for doc in results]
        return max(versions, default=0)

    return results
```

#### **How It Works**

* Queries **MongoDB** for all prompts related to a specific user.
* Returns:
  * **All results** if `get_latest_version` is **False**.
  * **Only the latest version** if `get_latest_version` is **True**.


---

# 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.groclake.ai/lakes/agent-management-and-deployment/promptlake/fetching-a-prompt.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.
