> ## Documentation Index
> Fetch the complete documentation index at: https://docs.wisdom.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Context Modeling Workflow

This guide outlines the complete, multi-step process for modeling your business Context in WisdomAI. The steps are:

1. [Build the foundation](#step-1-build-the-foundation-with-a-semantic-layer)
2. [Define complex Metrics](#step-2-define-complex-metrics-with-reviewed-queries)
3. [Refine and harden your logic](#step-3-refine-and-harden-your-logic)
4. [Test and measure your impact](#step-4-test-and-measure-your-impact)

The sections below describe each step of this workflow.

## Step 1: Build the foundation with a semantic layer

Before you can tackle complex analysis, you must establish a solid foundation. This involves creating a business-friendly semantic layer over your raw database structures and enriching it with basic, domain-specific language.

* **What you'll do**: Document tables and columns, define business entities, establish relationships, and add simple rules using natural language context.
* **How to do it**: For a detailed walkthrough, refer to our guide on [Advanced Data Modeling: Creating Context](/setting-up-wisdom-ai/advanced-data-modeling-creating-context).

## Step 2: Define complex Metrics with Reviewed Queries

For specific business calculations where an exact SQL structure is required, you should provide the AI with pre-vetted examples. This is ideal for complex metrics that might need window functions or nested queries.

* **What you'll do**: Create a library of **Reviewed Queries** by pairing a natural language question with its ideal SQL response.
* **How to do it**: The creation process is covered in our guide on [Advanced Data Modeling: Creating Context](/setting-up-wisdom-ai/advanced-data-modeling-creating-context).

## Step 3: Refine and harden your logic

Once your foundational context is in place, you can apply advanced strategies to make your logic more robust, maintainable, and accurate.

### Optimize your SQL for Reviewed Queries

The structure of your SQL has a significant impact on clarity and reusability. Follow these best practices to write more effective queries.

* **Use Common Table Expressions (CTEs) for clarity.** For complex logic, breaking the query into understandable CTEs makes it more readable and allows for reuse in future metrics.
* **Maintain consistent structures for related metrics.** When creating multiple variations of a metric, use a shared CTE to define the base calculation. This prevents logic from drifting between different reports.

### Combine Knowledge types for greater accuracy

In some complex cases, the AI might not follow an SQL example perfectly, leading to logical errors like double-counting. You can prevent this by supplementing your Validated Queries with explicit instructions in the Language Knowledge.

For example, if there is a pre-aggregated `country_population` column in a `statewise_population` table, adding `country_population` across states in the same country would lead to double-counting. An instruction might help to make sure this never happens; add a rule like: `"Never sum up country_population column across different rows for the same country"` to prevent incorrect aggregations.

## Step 4: Test and measure your impact

Knowledge modeling is an iterative process. To validate your improvements and track accuracy over time, you must continuously test your setup using a dedicated evaluation framework.

* **What you'll do**: Create **Evaluation Sets** containing test prompts and their expected SQL outputs, run evaluations, and analyze the reports to identify areas for improvement.
* **How to do it**: Learn the complete testing workflow in our guide, [Use Evaluations Sets and Runs](/improve-wisdom-ai-responses/use-evaluations-sets-and-runs).

## Next steps

<CardGroup cols={3}>
  <Card title="Auditing" icon="clipboard-list" href="/using-wisdom-ai-everyday/auditing">
    Review query history and system activity to ensure compliance and accuracy.
  </Card>

  <Card title="Provide Feedback to the System" icon="thumbs-up" href="/setting-up-wisdom-ai/feedback-mechanisms/provide-feedback-to-the-system">
    Learn how to rate answers and provide corrections to improve the system's accuracy.
  </Card>

  <Card title="Validate and Test Answers" icon="check-double" href="/improve-wisdom-ai-responses/validate-and-test-answers">
    Understand the methods for verifying the correctness and reliability of generated answers.
  </Card>
</CardGroup>
