Legacy Edge Logo

Category: AI Automation

  • How to Build an AI Pricing Model Using Machine Learning in Python

    How to Build an AI Pricing Model Using Machine Learning in Python

    In today’s competitive markets, pricing has become one of the most powerful levers for profitability — and one of the hardest to get right. Traditional pricing methods, like simple margin targets or “last price quoted” rules, can overlook complex relationships between cost, demand, competition, and customer behavior.

    That’s where Machine Learning (ML) comes in. By analyzing large volumes of historical quote and sales data, an AI Pricing Model can uncover hidden patterns — such as how product category, lead time, customer tier, or market conditions influence the probability of winning a quote or achieving a target gross profit.

    In this post, we’ll walk through how to build an AI Pricing Model using Machine Learning in Python, using tools like pandas, scikit-learn, and XGBoost. You’ll learn not just how the model works, but also why it can outperform traditional pricing logic — and how to interpret the model’s predictions in a way that’s practical for business decision-making.

    By the end, you’ll understand how to:

    • Prepare and clean pricing data for machine learning,
    • Train and evaluate a predictive pricing model,
    • Measure model accuracy using metrics like RMSE, R², and AUC,
    • and apply your AI pricing model to generate optimized prices that balance margin and win probability.

    Why Machine Learning Works for Pricing Optimization

    At its core, pricing optimization is about understanding how different factors — such as cost, competition, customer type, quantity, and lead time — influence a buyer’s willingness to pay and your ability to win profitable deals. The challenge is that these relationships are rarely linear or static. They can shift over time, differ across product categories, and interact in subtle ways that are hard to detect with traditional rule-based logic or spreadsheets.

    That’s exactly where Machine Learning (ML) excels.

    A Machine Learning model for pricing learns directly from historical quote and sales data. It doesn’t rely on hard-coded formulas; instead, it identifies patterns and correlations that may not be obvious to humans. For example, it might learn that:

    • A certain customer tier consistently pays higher prices for small-quantity orders,
    • Or that short lead times increase win probability but reduce achievable margins,
    • Or that specific product categories are more price-sensitive during certain market conditions.

    Because ML models can analyze millions of records at once, they’re capable of understanding these complex interactions and weighting them appropriately. The result is an AI Pricing Model that predicts outcomes such as:

    • Win probability for a given quote price, or
    • Expected gross profit (GP%) given market and customer conditions.

    With those predictions, pricing teams can simulate “what-if” scenarios — such as, “What happens to win probability if we increase price by 3%?” — and make more confident, data-driven decisions.

    Dynamic Learning and Adaptability

    Another reason Machine Learning works so well for pricing optimization is its ability to evolve. As new data is collected — from market shifts, supply chain changes, or customer behavior — the model can be retrained to learn from recent patterns. This makes it inherently adaptive, unlike static pricing rules that quickly become outdated.

    From Insight to Action

    When combined with explainability tools like SHAP (SHapley Additive exPlanations), businesses can even interpret why the model made certain pricing recommendations. This transparency builds trust and ensures that AI-driven pricing decisions are both accurate and explainable — not just “black box” outputs.

    Two Core Models Behind an AI Pricing Framework: Regression and Classification

    A strong AI Pricing Model using Machine Learning in Python usually isn’t just one model — it’s a combination of two that work together to predict both what price to quote and how likely you are to win at that price. These are called regression models and classification models, and each plays a distinct but complementary role.


    1. The Regression Model — “What GP% should we expect (or recommend)?”

    Think of the regression model as the price-setting brain of your AI Pricing system.

    It answers questions like:

    “Given these conditions — product group, customer tier, lead time, and market — what gross profit percentage (GP%) should we expect on this quote?”

    The model learns from past quotes where you know both the inputs (features such as customer, product, and quantity) and the outcome (the GP% you actually achieved).

    Over time, it learns relationships like:

    • “High-volume orders tend to have lower GP%,”
    • “Certain customers consistently negotiate tighter margins,”
    • “Stock items can carry higher GP% due to faster availability.”

    By understanding these patterns, the regression model can predict the most reasonable or competitive GP% for a new quote — effectively recommending a data-driven price point that aligns with historical success patterns.


    2. The Classification Model — “What’s the probability we’ll win this quote?”

    If the regression model helps you set the price, the classification model helps you evaluate the risk and opportunity of that price.

    This model predicts a win probability — essentially answering:

    “Given this quote’s characteristics and price level, what’s the likelihood that the customer will award us the order?”

    It learns from historical data labeled as won or lost. For each quote, it examines factors such as:

    • Quoted GP% (price competitiveness),
    • Customer relationship or tier,
    • Lead time,
    • Product category or market conditions.

    The output is a probability — for example, “There’s a 72% chance of winning this quote at this price.”

    With that, your pricing system can balance profit vs. win likelihood, enabling smarter trade-offs — such as lowering margin slightly on a high-probability deal or holding firm on price when the odds of winning are already low.


    When You Combine the Two

    When you use both models together, you get a complete AI Pricing Framework:

    • The Regression Model recommends a target price or GP%,
    • The Classification Model estimates the win probability at that price,
    • And together they create a feedback loop that helps your team find the optimal price point — the one that maximizes both revenue and likelihood of success.

    This combination mirrors what experienced sales or pricing analysts do intuitively — except the AI can analyze millions of records and update itself continuously as new data comes in.

    Tools and Frameworks in Python for Building an AI Pricing Model

    One of the biggest advantages of building an AI Pricing Model using Machine Learning in Python is that the Python ecosystem already provides powerful, production-ready libraries for every stage of the workflow — from cleaning your data to training, evaluating, and explaining the model’s predictions.

    Below are the key tools you’ll use, and the role each one plays in developing a pricing optimization framework.


    1. pandas — The Data Preparation Workhorse

    Before you can train a model, your quote and sales data needs to be cleaned and structured.

    That’s where pandas comes in. It’s a Python library designed for working with tabular data — like your pricing history — using simple, spreadsheet-like commands.

    With pandas, you can:

    • Load CSVs or Excel files into DataFrames,
    • Handle missing or invalid data,
    • Create new features (e.g., “lead_time_days” or “customer_tier”),
    • Filter, sort, and group data by product or customer,
    • Join multiple datasets (e.g., cost data with quote history).

    In short: pandas is where you prepare your pricing dataset for Machine Learning.

    import pandas as pd
    
    df = pd.read_csv("quotes.csv")
    df['lead_time_days'] = (df['expected_ship_date'] - df['quote_date']).dt.days
    

    2. scikit-learn — The Foundation for Machine Learning

    Once your data is ready, scikit-learn provides the essential tools for building and evaluating models.

    It includes algorithms for both regression and classification, along with utilities for:

    • Splitting your dataset into training and test sets,
    • Scaling and encoding data,
    • Evaluating model accuracy using metrics like RMSE, MAE, and (for regression) or AUC (for classification),
    • Building pipelines that make your ML workflow repeatable and organized.

    Even if you later switch to more advanced models like XGBoost, scikit-learn remains the framework that ties everything together.

    from sklearn.model_selection import train_test_split
    from sklearn.metrics import mean_absolute_error, r2_score
    

    3. XGBoost — High-Performance Predictive Modeling

    For real-world pricing problems, where data can include millions of quotes and dozens of features, XGBoost (Extreme Gradient Boosting) is a top performer.

    It’s a gradient-boosted decision tree algorithm known for:

    • Handling nonlinear relationships (e.g., between GP% and quantity),
    • Managing missing values gracefully,
    • Delivering high accuracy and fast training times.

    In your AI Pricing Model, XGBoost is typically used for both:

    • Regression → predicting the expected GP% for a quote,
    • Classification → predicting the probability of winning at that price.

    Its robustness and interpretability make it one of the most trusted algorithms for business-critical ML applications.

    import xgboost as xgb
    
    reg_model = xgb.XGBRegressor()
    clf_model = xgb.XGBClassifier()
    

    4. SHAP (SHapley Additive exPlanations) — Explaining the Model

    Even the most accurate AI pricing model isn’t useful if you can’t explain why it makes a certain recommendation.

    That’s where SHAP comes in. SHAP values quantify how much each feature — such as customer tier, lead time, or product group — contributes to a specific prediction.

    For example:

    • “Lead time contributed +1.2% to the GP% recommendation,”
    • “Customer tier lowered the win probability by 8%.”

    With SHAP visualizations, pricing analysts can see exactly what drives the model’s logic, turning complex AI outputs into actionable business insights.

    import shap
    
    explainer = shap.TreeExplainer(reg_model)
    shap_values = explainer.shap_values(X_test)
    shap.summary_plot(shap_values, X_test)
    

    Bringing It All Together

    When combined, these Python tools provide a complete end-to-end solution for building an AI Pricing Model:

    StageGoalTool
    Data preparationClean and organize quote datapandas
    Model trainingBuild regression and classification modelsscikit-learn, XGBoost
    Model evaluationMeasure accuracy and predictive powerscikit-learn metrics
    Model explainabilityVisualize feature importance and logicSHAP

    Together, these frameworks turn raw pricing history into a living, learning system — one that continuously refines your pricing strategy based on data, not gut feel.

    Step-by-Step: How to Build an AI Pricing Model Using Machine Learning in Python

    This walkthrough shows how to build the two-model framework:

    1. a Regression model to recommend a target GP%, and
    2. a Classification model to estimate win probability at a given price.

    We’ll use pandas, scikit-learn, XGBoost, and SHAP.

    Mini data-sanity checklist (save the deep dive for the next post):

    • Remove or flag obvious data errors (negative quantities/costs, GP% > 100, etc.).
    • Avoid leakage: for the win model, only use features available before the decision (e.g., do not use “won/lost” derived fields or post-quote info).
    • Ensure time awareness: train on older data, test on newer (or do time-based CV).
    • Encode categories (customer tier, product group/category) and handle missing values.

    1) Setup & Load Data

    import pandas as pd
    import numpy as np
    
    # Load your quotes dataset
    df = pd.read_csv("quotes.csv", parse_dates=["quote_date"], low_memory=False)
    
    # Example expected columns (adjust to your schema):
    # 'quoted_price', 'quoted_quantity', 'cost', 'quoted_gp_pct', 'won_flag',
    # 'product_group', 'product_category', 'customer_tier', 'lead_time_days',
    # 'is_stock_item', 'on_hand_qty_at_quote'
    

    Light cleaning:

    # Basic filters/sanity
    df = df.dropna(subset=["quoted_gp_pct", "won_flag", "product_group", "customer_tier"])
    df = df[(df["quoted_gp_pct"] > -20) & (df["quoted_gp_pct"] < 100)]  # tweak if needed
    
    # Ensure types
    df["is_stock_item"] = df["is_stock_item"].astype(int)  # 0/1
    df["won_flag"] = df["won_flag"].astype(int)  # 0/1
    

    2) Feature Sets for Each Model

    • Regression (target = quoted_gp_pct)
      Inputs that influence achievable margin: ['product_group', 'product_category', 'customer_tier', 'lead_time_days', 'is_stock_item', 'on_hand_qty_at_quote']
    • Classification (target = won_flag)
      Include the price signal (e.g., quoted_gp_pct) plus context features: ['quoted_gp_pct', 'product_group', 'product_category', 'customer_tier', 'lead_time_days', 'is_stock_item', 'on_hand_qty_at_quote']

    Tip: Keep feature names aligned between models so the system is easy to maintain. Avoid ‘feature leakage’ by not giving any features to the models that give away the answer (for example, do not give information about the actual price or GP% from the training data to the regression model, and do not give the outcome information to the classification model.) Also, remember that the information that is chosen to be used as a feature will be the same information that will be required to give the models later when using them to predict outcomes.


    3) Train/Test Split (time-aware if possible)

    # Option A: random split (simple)
    from sklearn.model_selection import train_test_split
    
    reg_features = ['product_group','product_category','customer_tier',
                    'lead_time_days','is_stock_item','on_hand_qty_at_quote']
    clf_features = ['quoted_gp_pct'] + reg_features
    
    X_reg = df[reg_features]
    y_reg = df["quoted_gp_pct"]
    
    X_clf = df[clf_features]
    y_clf = df["won_flag"]
    
    Xr_train, Xr_test, yr_train, yr_test = train_test_split(X_reg, y_reg, test_size=0.2, random_state=42)
    Xc_train, Xc_test, yc_train, yc_test = train_test_split(X_clf, y_clf, test_size=0.2, random_state=42)
    
    # Option B (recommended for production): split by date so test is newer period
    

    4) Preprocessing Pipelines

    from sklearn.compose import ColumnTransformer
    from sklearn.preprocessing import OneHotEncoder
    from sklearn.pipeline import Pipeline
    from sklearn.metrics import mean_absolute_error, r2_score, mean_squared_error, roc_auc_score
    import xgboost as xgb
    import numpy as np
    
    cat_cols = ['product_group','product_category','customer_tier']
    num_cols = ['lead_time_days','is_stock_item','on_hand_qty_at_quote']
    
    preprocessor = ColumnTransformer(
        transformers=[
            ("cat", OneHotEncoder(handle_unknown="ignore"), cat_cols),
            ("num", "passthrough", num_cols)
        ]
    )
    

    5) Train the Regression Model (GP% recommender)

    reg_model = xgb.XGBRegressor(
        n_estimators=600,
        max_depth=6,
        learning_rate=0.05,
        subsample=0.9,
        colsample_bytree=0.9,
        random_state=42,
        n_jobs=-1
    )
    
    reg_pipe = Pipeline([
        ("prep", preprocessor),
        ("model", reg_model)
    ])
    
    reg_pipe.fit(Xr_train, yr_train)
    
    # Evaluate
    yr_pred = reg_pipe.predict(Xr_test)
    rmse = np.sqrt(mean_squared_error(yr_test, yr_pred))
    mae = mean_absolute_error(yr_test, yr_pred)
    r2 = r2_score(yr_test, yr_pred)
    
    print(f"Regression — RMSE: {rmse:.3f} | MAE: {mae:.3f} | R²: {r2:.3f}")
    

    6) Train the Classification Model (win probability)

    clf_model = xgb.XGBClassifier(
        n_estimators=600,
        max_depth=6,
        learning_rate=0.05,
        subsample=0.9,
        colsample_bytree=0.9,
        random_state=42,
        n_jobs=-1,
        eval_metric="auc"
    )
    
    # Preprocessor is the same structure, but includes quoted_gp_pct as numeric
    cat_cols_c = cat_cols
    num_cols_c = ['quoted_gp_pct','lead_time_days','is_stock_item','on_hand_qty_at_quote']
    
    preprocessor_clf = ColumnTransformer(
        transformers=[
            ("cat", OneHotEncoder(handle_unknown="ignore"), cat_cols_c),
            ("num", "passthrough", num_cols_c)
        ]
    )
    
    clf_pipe = Pipeline([
        ("prep", preprocessor_clf),
        ("model", clf_model)
    ])
    
    clf_pipe.fit(Xc_train, yc_train)
    
    # Evaluate
    yc_pred_proba = clf_pipe.predict_proba(Xc_test)[:,1]
    auc = roc_auc_score(yc_test, yc_pred_proba)
    print(f"Classification — AUC: {auc:.3f}")
    

    7) Explainability with SHAP (optional but recommended)

    import shap
    
    # For tree-based models, explain on the transformed matrix
    # Grab a small sample to keep plots fast
    sample = Xr_test.sample(n=min(2000, len(Xr_test)), random_state=42)
    
    # Fit a TreeExplainer on the trained XGB model inside the pipeline
    # We need the model object (reg_model) and the transformed features
    X_sample_transformed = reg_pipe.named_steps["prep"].transform(sample)
    explainer = shap.TreeExplainer(reg_pipe.named_steps["model"])
    shap_values = explainer.shap_values(X_sample_transformed)
    
    # Summary plot (run in notebooks)
    # shap.summary_plot(shap_values, X_sample_transformed, feature_names=reg_pipe.named_steps["prep"].get_feature_names_out())
    

    Tip: For reports, capture SHAP bar plots for top features affecting GP% and win probability. This builds trust with commercial teams.


    8) Put the Models to Work: Recommend a Price & Simulate Win Probability

    Flow in production for a new quote:

    1. Use the regression model to recommend a baseline GP%.
    2. Convert GP% → price (based on cost).
    3. Create a small price ladder around that recommendation (±2–5 percentage points).
    4. For each rung, compute win probability via the classification model.
    5. Pick the rung that meets your business objective (e.g., maximize expected margin = margin × win_prob, or enforce a minimum win probability).

    Example:

    def gp_to_price(cost, gp_pct):
        # gp_pct as percentage number, e.g., 25 means 25%
        return cost / (1 - gp_pct/100.0)
    
    def simulate_ladder(row, reg_pipe, clf_pipe, ladder_pts=(-4,-2,0,2,4)):
        # 1) Predict baseline GP%
        reg_input = row[reg_features].to_frame().T
        gp_base = float(reg_pipe.predict(reg_input))
    
        results = []
        for delta in ladder_pts:
            gp_try = max(min(gp_base + delta, 95), -5)  # clamp
            price_try = gp_to_price(row["cost"], gp_try)
    
            clf_input = row[clf_features].copy()
            clf_input["quoted_gp_pct"] = gp_try
            win_prob = float(clf_pipe.predict_proba(clf_input.to_frame().T)[:,1])
    
            margin = price_try - row["cost"]
            expected_margin = margin * win_prob
    
            results.append({
                "gp_pct": round(gp_try,2),
                "price": round(price_try,2),
                "win_prob": round(win_prob,3),
                "expected_margin": round(expected_margin,2)
            })
        return pd.DataFrame(results).sort_values("expected_margin", ascending=False)
    
    # Example usage on a single quote row (replace with real row)
    # row = df.iloc[0]
    # ladder = simulate_ladder(row, reg_pipe, clf_pipe)
    # display(ladder)
    

    9) Save & Load Models

    import joblib
    joblib.dump(reg_pipe, "gp_regression_pipe.joblib")
    joblib.dump(clf_pipe, "win_classifier_pipe.joblib")
    
    # Later
    # reg_pipe = joblib.load("gp_regression_pipe.joblib")
    # clf_pipe = joblib.load("win_classifier_pipe.joblib")
    

    10) Production Tips

    • Time-based validation: use rolling windows to ensure robustness across market regimes.
    • Segmented models: consider separate models by product category if behavior differs drastically.
    • Guardrails: enforce GP% floors/ceilings by customer tier or category.
    • Monitoring: track drift in feature distributions and periodic re-train cadence (monthly/quarterly).

    Conclusion: Turning Data Into Dynamic Pricing Decisions

    Building an AI pricing model with Python transforms pricing from guesswork into a measurable, data-driven strategy. By combining regression and classification models with tools like pandas, scikit-learn, XGBoost, and SHAP, businesses can predict both the optimal price and the probability of winning at that price — all while understanding why the model makes its recommendations. The result is a pricing framework that adapts to changing markets, maximizes profit margins, and empowers your team to make confident, intelligent decisions. As AI continues to reshape competitive industries, developing your own machine learning pricing model isn’t just a technical advantage — it’s a strategic one.

  • AI-Powered Email Automation

    AI-Powered Email Automation

    How to use AI to determine the sender’s intent from Office365 emails

    Inbound email Inbound still drives a shocking amount of work inside most companies. Examples you’ll recognize:

    • “Please quote 250 EA of PN-4321.”
    • “Attached is PO‑98765”
    • “What’s the status on order 12345?”
    • “Send tracking for yesterday’s shipment.”

    If a human must open each message, interpret it, save attachments, run a script, and route folders, you lose hours and introduce errors.

    Classifying the intent of each email the moment it arrives unlocks automation. Your flow can branch to send quotes, process purchase orders, trigger status lookups, and more—consistently and at scale.

    What you’ll build

    A Microsoft Power Automate cloud flow that:

    1. Reads new emails
    2. Converts HTML to text
    3. Uses an LLM prompt to categorize the message
    4. Parse the JSON response from the LLM
    5. Gates on confidence
    6. Switches on intent
    7. Takes appropriate actions based on the sender’s intent

    Prerequisites: Microsoft Office 365 Outlook and Microsoft Power Automate Cloud

    High-level-flow

    Trigger HTML to text Run an AI prompt Parse JSON response Condition (confidence) Switch (intent) Per-intent actions

    Step-by-step

    1. Create the flow and set the trigger

    In Microsoft’s Power Automate, select My Flows and then New Flow – Automated cloud flow:

    Give the new flow a descriptive name, and choose the trigger: When a new email arrives (V3). Click Create.

    The flow will be shown in Map View:

    Click the first (and only) action shown in the Map View of the flow to reveal the Settings panel, which will usually appear on the left side of the screen.

    Select Folder under the Advanced parameters dropdown list and select the email folder that you are interested in having the trigger action monitor (usually Inbox).

    Set any other Advanced parameters that might apply for your automation. Another common parameter that is changed is the Include Attachments parameter, it is often set to Yes.

    2. Convert the email body to text

    Emails are often sent in HTML format. The automation will be more reliable if we convert the body of those emails to text.

    Add a 2nd action by clicking the “+” button below the first. Search for the action named Html to text and click it to add it to the flow.

    In the Settings panel for the new action, click in the Content box, then click the blue lightening icon to insert dynamic content.

    A list of available dynamic content will appear. From the list of dynamic content, select Body from the previous step.

    Tip: There are quite a few outputs from the previous step that are not shown. If Body is not listed, click See More to see the additional dynamic content options.

    This will cause the body of the email to be dynamically inserted into the Content that will be converted to text.

    3. Use AI to categorize the email, returning a JSON response.

    Add another action to the flow. Select the action named Run a prompt.

    In the Settings, for the new action, under the Parameters tab, click the drop-down arrow under Prompt and select New custom prompt.

    Insert the following prompt into the Instructions textbox:

    You are an assistant that categorizes inbound emails.
    Your task: Analyze the email subject and body, then return ONLY valid JSON that matches this schema:
    {
      "intent": "quote_request | purchase_order | other",
      "confidence": 0.0-1.0,
      "summary": "A one-sentence summary of the email"
    }
    Definitions:
    - "quote_request": The sender is asking for pricing, a quote, or availability for one or more items.
    - "purchase_order": The sender is sending a Purchase Order (PO) in response to a quote or pricing you previously sent them.
    - "other": Anything that is not a quote request or a purchase order.
    Guidelines:
    - Always output JSON only, with no explanatory text.
    - confidence should be between 0.0 and 1.0 indicating how certain you are of the classification.
    - summary should be a short, plain English sentence.
    EMAIL_SUBJECT:
    EMAIL_BODY:

    Tip: This example shows you how you can process purchase orders automatically and respond to customer quotes automatically. Customize the above prompt to your needs. For example, change the list of intents to match the intents that you desire the AI to categorize. When you do so, make sure you modify the expected JSON schema below in step #4 to match your modifications.

    Dynamically inserting the email subject and body into the prompt

    You’ll notice that there is no text after the EMAIL_SUBJECT and EMAIL_BODY tags in the above prompt.

    Place your cursor after the words EMAIL_SUBJECT in the prompt, add a space, and then enter a forward-slash “/” character. Doing so will bring up a context menu that looks like the following:

    Select Text to choose a text input, then name the input email_subject. (You do not need to enter any sample data). Click Close on the context window.

    You’ll notice a new placeholder inserted in the prompt next to EMAIL_SUBJECT with the name email_subject, and at the bottom of the Instructions textbox you will see ‘1 input’.

    Follow the same pattern to add another Text input named email_body next to the text EMAIL_BODY. Now you should see ‘2 inputs’ at the bottom of the Instructions textbox:

    Click Save at the bottom right of the screen.

    The two inputs (Email_body and Email_subject) are now available to be set under the Parameters tab:

    Click in the text box for Email_body, click the blue lightening bolt icon and select The plain text content output from the previous step Html to text.

    Select the Subject from the When a new email arrives (V3) action as the dynamic content for the Email_subject.

    4. Parse the JSON returned from the LLM

    Add a Parse JSON action to the flow.

    Tip: Actions can be conditionally called upon success or failure of previous actions. For complicated actions that have a chance of failure (like the Run a Prompt action above), condition the next action to only fire upon a successful completion of the previous action. When hardening this solution for production, consider changing the Setting for the Parse JSON action to only fire if the Run a Prompt action is successful. Define another action to handle the error flow if the previous action fails or times out.

    Under its Parameters, select the Text output from the Run a Prompt as the dynamic content for the Content parameter.

    The other parameter setting of this action needs to describe the JSON schema that should be expected. Enter the following into Schema:

    {
      "type": "object",
      "properties": {
        "intent": {
          "type": "string",
          "enum": ["quote_request","purchase_order","other"]
        },
        "confidence": { "type": "number" },
        "summary": { "type": "string" }
      },
      "required": ["intent","confidence","summary"]
    }

    Tip: Don’t forget to modify the above schema to match the list of intents that you want to categorize, from step #3 above.

    5. Gate on confidence

    Add a Condition action to the flow. In its Parameters, click in the box labeled Choose a value, click the blue lightening bolt to insert dynamic content and choose the Body confidence output from the Parse JSON action.

    Set the condition is greater than or equal to 0.90.

    Tip: Tune this confidence score as needed.

    If False: you have several options here. For example, you can put no actions below this condition to basically ignore emails that arrive in the monitored folder that the AI was not highly confident matched a specified intent. Or, you could add actions here to move the email to another folder for a human to review.

    If True: continue to the next step, Switch on intent.

    6. Switch on intent

    Add a Switch action to the flow under the True condition.

    In the On parameter, click in the box labeled Choose a value, then click on the blue lightening bolt and select Body intent from the Parse JSON action as dynamic content.

    In the Map View, there is a “+” button below the Switch action, as well as a Default case.

    Click the “+” button to the left of the Default case to add a case. In the Equals parameter, enter one of the intents, such as “quote_request”.

    Tip: For readability in the Map View, click ‘Case’ to change the name of the case from ‘Case’ to ‘Quote_Request’.

    Follow the same pattern to add the other cases below the Switch action, for example, “purchase_order”.

    7. Continue the flow for each intent

    Click the “+” button under each intent (and potentially the ‘Default’ case too) to perform your desired actions for each intent. An excellent next step in the flow may be to extract a list of items from the content. Refer to the article How to Extract Items and Quantities from Emails, PDFs and Excel using AI to learn how to perform that step.

    Summary

    This post has shown how to achieve Office365 email automation using Microsoft Power Automate and AI to automatically classify incoming emails by intent—such as quote requests, purchase orders, or other messages. This method of AI email categorization will save your business time, reduce errors, and streamline the processes that are triggered by emails.