← All articlesAzure

Build a Contract & RFP Analysis Agent with Azure AI Foundry and Azure AI Search

Ishfaq Nazir · Microsoft & Azure Cloud Security Architect 10/14/2026 13 min read

When to choose Azure AI Foundry

Copilot Studio is the right low-code choice for most business agents. Choose Azure AI Foundry when you need:

  • Full control over models, prompts and evaluation.
  • Large document volumes and custom indexing (tables, clauses, long PDFs).
  • Integration into your own applications through an API.
  • Network isolation with private endpoints.

Business scenario

The legal and procurement team reviews 30 vendor contracts and RFP responses each month, each 50–200 pages. They want an agent that can:

  • Answer "What is the limitation of liability in the Fabrikam MSA?" with the exact clause.
  • Compare payment terms across all vendor responses.
  • Flag clauses that deviate from the company's standard positions.

Architecture

  • Azure Blob Storage — stores the contracts.
  • Azure AI Document Intelligence — extracts text, tables and layout from PDFs.
  • Azure AI Search — hybrid (keyword + vector) index with semantic ranking.
  • Azure OpenAI in Azure AI Foundry — GPT-4o (or newer) for reasoning, text-embedding-3-large for embeddings.
  • Azure AI Foundry Agent Service — hosts the agent, its instructions and tools.
  • Microsoft Entra ID and managed identities — no keys in code.

Prerequisites

  1. An Azure subscription with access to Azure OpenAI.
  2. Contributor rights on a resource group.
  3. A sample set of 10–20 contracts for testing.
  4. A list of your standard clause positions (the "playbook").

Step 1 — Create the Foundry project

  1. Go to ai.azure.com and create a new project.
  2. Deploy models: a chat model (for example gpt-4o) and an embedding model (text-embedding-3-large).
  3. Assign your user and the project's managed identity the roles they need (Azure AI User, Search Index Data Reader, Storage Blob Data Reader).

Step 2 — Ingest and index documents

  1. Upload contracts to a Blob container.
  2. In Azure AI Search, use Import and vectorize data, select the container, and choose Document Intelligence layout parsing so headings and tables are preserved.
  3. Chunk by section (for example 1,000–2,000 tokens with overlap) so each clause stays together.
  4. Add metadata fields: vendor name, contract type, effective date. These enable filtering.
  5. Enable semantic ranking for better relevance.

Step 3 — Create the agent

In the Foundry portal, open Agents and create a new agent:

You are a contract analysis assistant for the Contoso legal team.
- Answer only from the indexed contracts.
- Always quote the clause text and give document name and section number.
- When asked to review, compare each clause against the Contoso playbook
  and label it: Standard, Acceptable deviation, or High risk.
- If information is not in the documents, say "Not found in the contracts."
- You do not give legal advice; you support lawyers.

Attach the Azure AI Search index as a knowledge tool. Upload the playbook as a file for the file search tool.

Step 4 — Call the agent from code

from azure.identity import DefaultAzureCredential
from azure.ai.projects import AIProjectClient

client = AIProjectClient(
    endpoint="https://<your-resource>.services.ai.azure.com/api/projects/<project>",
    credential=DefaultAzureCredential(),
)

agent = client.agents.get_agent("<agent-id>")
thread = client.agents.threads.create()
client.agents.messages.create(
    thread_id=thread.id, role="user",
    content="List the termination clauses in all Fabrikam contracts.")
run = client.agents.runs.create_and_process(thread_id=thread.id, agent_id=agent.id)

for m in client.agents.messages.list(thread_id=thread.id):
    print(m.role, m.content)

Step 5 — Evaluate before release

  1. Build a test set of 50 questions with the correct answers and clause references.
  2. Use Foundry evaluations to score groundedness, relevance and coherence.
  3. Have a lawyer review a sample of answers. Do not release until groundedness is consistently high.

Step 6 — Add safety controls

  • Azure AI Content Safety with Prompt Shields to detect prompt injection hidden inside uploaded documents.
  • Security-trimmed search: store an allowed-groups field per document and filter queries by the user's Entra groups.
  • Private endpoints for Search, Storage and Azure OpenAI; disable public network access.
  • Diagnostic logs to Log Analytics; Defender for Cloud threat protection for AI workloads.

Step 7 — Deliver it to users

Options, from simplest to most custom:

  1. Publish the agent to Microsoft 365 Copilot and Teams.
  2. Build a small internal web app on Azure App Service with Entra sign-in.
  3. Connect it as a tool to a Copilot Studio agent for the wider business.

Cost tips

  • Use a smaller model (for example gpt-4o-mini) for classification and summaries; reserve larger models for review.
  • Re-index only changed files.
  • Set budgets and alerts in Azure Cost Management.

Learn more

  • Microsoft Learn: Azure AI Foundry Agent Service — https://learn.microsoft.com/azure/ai-foundry/agents/overview
  • Microsoft Learn: RAG with Azure AI Search — https://learn.microsoft.com/azure/search/retrieval-augmented-generation-overview
#Azure AI Foundry#Azure OpenAI#AI Agents#RAG

Related articles