# Expense Policy Decision Engine (Policy API Integration)

<details>

<summary>In Progress</summary>

This page is currently under active development. Content may be incomplete, evolving, or placeholder-only. Please check back later for finalized documentation and fully structured examples.

</details>

This Expense Policy Decision Engine (Policy API Integration) template is a workshop that builds on the [Threshold Memory version](/templates/policy-automation/expense-policy-decision-engine/expense-policy-decision-engine-threshold-memory.md) of the [Expense Policy Decision Engine series of templates](/templates/policy-automation/expense-policy-decision-engine.md) and introduces a simulated API integration. Instead of using a real external API, this class uses GLIK Knowledge to simulate an API response containing policy rules (such as spending thresholds and vendor blacklists).

Participants will:

* Learn how to use the [**Knowledge Retrieval Block**](/system-architecture/blocks-and-nodes/input-and-extraction/knowledge-retrieval.md) to simulate calling an external policy API.
* Dynamically assign and evaluate retrieved rules in an expense approval workflow.
* Understand how internal knowledge objects can act as structured data endpoints.

This simulation sets the stage for connecting to real enterprise APIs in later stages.

***

### 🛠️ What You’ll Build

A workflow that:

* Accepts an uploaded invoice file
* Extracts invoice metadata
* Retrieves policy rules (thresholds, blacklists) from GLIK Knowledge
* Applies conditional logic to approve, reject, or escalate
* [Falls back to LLM reasoning](/system-architecture/blocks-and-nodes/input-and-extraction/llm-block/fallback-to-llm-reasoning.md) if no rule applies

***

### 🧩 Workflow Structure

{% embed url="<https://www.mermaidchart.com/raw/e129208d-2b42-4d65-9e70-b1b2922f8095?theme=light&version=v0.1&format=svg>" %}
Simulates an API integration using GLIK Knowledge. The uploaded invoice is extracted and evaluated against policy rules retrieved via a tag-based knowledge query. If the logic is ambiguous or unmatched, an LLM block provides fallback reasoning before issuing a final approval, rejection, or escalation decision.
{% endembed %}

### 📂 Step-by-Step Instructions

#### 1. **Create or Upload a Sample Policy in GLIK Knowledge**

Create a new memory object with the following JSON content:

```json
{
  "policy_id": "demo_policy_001",
  "threshold": 3000,
  "blacklist": ["ACME Consulting", "Shady Corp"],
  "categories": {
    "travel": 1000,
    "equipment": 5000
  }
}
```

Apply these tags:

* `type:policy`
* `demo:true`

***

#### 2. **Build the Workflow in GLIK Studio**

**Required Blocks:**

* 📥 **Start**
* 📄 **Doc Extractor**
* 🧠 **Knowledge Retrieval Block** (query: `type:policy AND demo:true`)
* 🧮 **Conditional Block** (compare values from `invoice_data` to `policy_memory`)
* 🤖 **LLM Block** (fallback)
* ✅ **Answer or End Block**

**Variables Used:**

* `invoice_data`
* `policy_memory`
* `approval_result`
* `conversation_notes`

***

### 🧪 Practice Exercises

* Modify the policy memory with a tighter threshold
* Add a new blacklisted vendor
* Re-upload the workflow and re-run with different invoice PDFs to test the logic path

***

### 🧠 Key Concepts&#x20;

* Structured data in memory vs. static config
* Simulated API integration
* Conditional logic based on dynamic variables
* Querying GLIK Knowledge by tag
* Using fallback reasoning for exception cases

***

### 📌 Next Steps

After this class, learners are ready to:

* Integrate real external APIs (e.g., using `API Call` blocks)
* Use branching logic to support multi-policy contexts
* Expand the workflow into a full Expense Audit Engine


---

# 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.glik.ai/templates/policy-automation/expense-policy-decision-engine/expense-policy-decision-engine-policy-api-integration.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.
