Using Office365 SearchEmailsInput in LangChain
Posted: Feb 1, 2025.
When working with Office365 email integration in LangChain, the SearchEmailsInput class provides a structured way to search and filter emails using Microsoft Graph API queries. This guide will show you how to effectively use this class to search through your Office365 emails.
What is SearchEmailsInput?
SearchEmailsInput is a Pydantic model class that defines the input parameters for searching emails in Office365 using LangChain. It provides a structured way to specify search criteria, including query filters, folder selection, and result limitations.
Reference
Here are the available parameters for SearchEmailsInput:
Parameter | Type | Default | Description |
---|---|---|---|
query | str | Required | Microsoft Graph v1.0 search query string |
folder | str | None | Target folder to search in (e.g., "inbox", "drafts") |
max_results | int | 10 | Maximum number of results to return |
truncate | bool | True | Whether to truncate email body content |
How to Use SearchEmailsInput
Let's explore different ways to use SearchEmailsInput for searching emails.
Basic Search Query
Advanced Filtering
Search with Attachments Filter
Combined Search Parameters
Query Syntax Examples
The query
parameter supports various search filters. Here are some useful examples:
-
Date Filtering:
-
Recipient Filtering:
-
Content Filtering:
Best Practices
- Set
truncate=True
when dealing with large email bodies to avoid token limits - Use specific folders when possible to narrow down search scope
- Combine multiple filters to create precise search queries
- Use reasonable
max_results
values to manage response size
Remember that the actual email search will need to be performed using an Office365 email tool that accepts this SearchEmailsInput instance. This class only defines the search parameters and doesn't perform the actual search operation.
An alternative to LangSmith
Open-source LangChain monitoring, prompt management, and magic. Get started in 2 minutes.
LangChain DocsJoin 10,000+ subscribers
Every 2 weeks, latest model releases and industry news.
An alternative to LangSmith
Open-source LangChain monitoring, prompt management, and magic. Get started in 2 minutes.