# 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](https://docs.glik.ai/templates/policy-automation/expense-policy-decision-engine/expense-policy-decision-engine-threshold-memory) of the [Expense Policy Decision Engine series of templates](https://docs.glik.ai/templates/policy-automation/expense-policy-decision-engine) 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**](https://docs.glik.ai/system-architecture/blocks-and-nodes/input-and-extraction/knowledge-retrieval) 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](https://docs.glik.ai/system-architecture/blocks-and-nodes/input-and-extraction/llm-block/fallback-to-llm-reasoning) 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
