> For the complete documentation index, see [llms.txt](https://docs.apryse.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.apryse.com/core/augmenting-llms-with-smart-data-extraction/documentcontextexample.md).

# Using Smart Data Extraction to Augment Contextual LLM Queries - Document Context Example

Learn how to include document context in a query to an LLM with this example. Extract document structure info, convert to HTML, and run the command for results. Discover Retrieval Augmented Generation

## Example 1 - Document Context

The following is a simple example that shows how one might include document context with a query to an LLM, while leveraging information about the document structure contained in the PDF. The process can be broken down into a few steps:

1. Extract document structure information using the Apryse Smart Data Extraction Module
2. Convert the document structure information to a more concise and recognizable format. We have chosen HTML, which works well with Open AI's GPT.
3. Include the context and structure information in a query to the LLM.

To run the example, use the following command (with your virtual environment active, if using):

{% tabs %}
{% tab title="Shell" %}
{% code lineNumbers="true" %}

```sh
python3 ./doc_context.py
```

{% endcode %}
{% endtab %}
{% endtabs %}

You should see some text indicating progress, with a question and answer about the document appearing at the end. LLM's aren't guaranteed to produce identical output between runs, but you should see something similar to the following:

{% tabs %}
{% tab title="Shell" %}
{% code lineNumbers="true" %}

```sh
Extracting Document Structure from <your-absolute-path>/doc_context_guide/data/
    pdf/travel_expenses.pdf...
Extracted data to <your-absolute-path>c/doc_context_guide/data/output/
    doc_context_example/travel_expenses/json/travel_expenses.json

================================================================================

Question: How much did the employee spend on airfare?

Answer: To calculate the total amount spent on airfare by the employee, we need 
to sum up all the expenses categorized under "Travel" that specifically mention 
flights. According to the expense report, these are the relevant entries:

1. Flight to Toronto, ON, Canada (03/17/2023 - 03/20/2023): $500.00
2. Flight to Boston, MA, USA (05/01/2023 - 05/02/2023): $400.75
3. Flight to Toronto, ON, Canada (06/07/2023 - 06/08/2023): $450.25
4. Flight to Miami, FL, USA (08/19/2023 - 08/24/2023): $600.35

Adding these amounts together gives:

$500.00 + $400.75 + $450.25 + $600.35 = $1951.35

Therefore, the employee spent a total of $1951.35 on airfare.
```

{% endcode %}
{% endtab %}
{% endtabs %}

## Next Steps

[Document RAG Example](/core/augmenting-llms-with-smart-data-extraction/iso32000ragexample.md)

In this section, we introduce the concept of Retrieval Augmented Generation (RAG), and show how you can break down larger documents into searchable chunks to use with your queries.


---

# 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://docs.apryse.com/core/augmenting-llms-with-smart-data-extraction/documentcontextexample.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.
