Flow Actions

Query Document

Introduction

The CloudFiles: Query Document flow action enables to execute Natural Language Prompts on the data of the documents that have already been processed using Process Document using AI action.

Document image




What this action does

The CloudFiles: Query Document action allows you to execute a query (a natural language or English-language prompt) on the data of a processed document. The action processes the query and returns the result as a text output.

Imagine you are processing KYC files uploaded to Contact object records. Using this action, you can:

  1. Classify the uploaded document as a Driving License, Passport, or neither.
  2. Extract relevant information, such as the passport number, from the document.
  3. Update the corresponding fields on the Contact record.
  4. Classification Query:
    • Prompt: "Check the type of file. If it's a Driving License, return 1; if it's a Passport, return 2; if neither, return 0."
    • Based on the result (e.g., 2 for Passport), the flow decides the next steps.
  5. Decision Element:
    • Using the query result, the flow branches into specific paths for each document type.
  6. Follow-Up Queries:
    • For example, if the classification query returns 2 (Passport), the flow enters the "Is Passport" path and runs queries like:
      • "Extract the passport number."
      • "Extract the name on the passport."
Document image


By using multiple Query Document actions within a flow, you can build complex workflows that analyze and extract data from documents efficiently.

Input Parameters

Let us discuss each of the input parameters in detail, in the sections below.

Processed Document ID

Input the Processed Document ID of the file on which you wish to execute the Query.

The Processed Document ID is a unique identifier provided by CloudFiles that represents the data of a processed document.

How it is Generated ?

How to Retrieve It ?

  1. Use the Get Event Details flow action associated with the corresponding event to obtain the ID.
  2. Alternatively, if you need to execute queries on a Salesforce File later or on-demand:
    • Store the file's Processed Document ID in a custom Content Version field.
    • This allows you to query the document anytime, without relying on the event.

Note

The same Processed Document ID can be reused multiple times to reference the document and execute queries as needed.

Query

Input the Query (as a plain text) specifying the prompt you wish to execute on the file identified by the input Processed Document ID.

You can directly pass a string as the query (e.g., "Extract the passport holder's name."). Alternatively, you can pass the query dynamically through a variable, formula etc. allowing to incorporate complex use cases.

The effectiveness of the CloudFiles: Query Document action heavily depends on the quality of the query or input prompt.

Tips for Crafting Effective Prompts:

  • Be Specific: Avoid vague prompts like "Return Expiry Date of the Passport". Instead, use a more detailed query like: "Return the Expiry Date of the Passport in the format DD/MM/YYYY."
  • Define a return format statement as well which should cover all the expected outcomes in order to avoid garbage values and unprecedented results.
  • Test and Refine: You can test the quality of your queries and verify if they yield the desired results by using the Playground feature in the CloudFiles app.

Testing Queries in the Playground:

  1. Navigate to CloudFiles App > Document AI > Playground.
  2. Upload a sample file.
  3. Use the interactive Query side-component to experiment with different prompts against the file.
Document image


This iterative process helps you fine-tune your queries for optimal results before implementing them in your workflows.

Output Parameters

The output of the CloudFiles: Query Document action is a Text (String) data type containing the result of the query as defined in the query prompt.

Where to Find the Output ?

  • The action's output is available in the flow resource's Action section.
  • The output is named based on the corresponding action label. For example, If the action is labeled as "Full Dimension Table Data", the output flow resource will be named "Text from Full Dimension Table Data".
Document image


See It In Action

Here is the flow in action that we have used in this article as an example. In this flow we are providing a document to the AI and then prompting queries to determine whether the given document is KYC or not and classifying the type of KYC if it is either DL or passport.

Document image