Digital lending is a critical business enabler for banks and financial institutions. Customers apply for a loan online after completing the know your customer (KYC) process. A typical digital lending process involves various activities, such as user onboarding (including steps to verify the user through KYC), credit verification, risk verification, credit underwriting, and loan sanctioning. Currently, some of these activities are done manually, leading to delays in loan sanctioning and impacting the customer experience.
In India, the KYC verification usually involves identity verification through identification documents for Indian citizens, such as a PAN card or Aadhar card, address verification, and income verification. Credit checks in India are normally done using the PAN number of a customer. The ideal way to address these challenges is to automate them to the extent possible.
The digital lending solution primarily needs orchestration of a sequence of steps and other features such as natural language understanding, image analysis, real-time credit checks, and notifications. You can seamlessly build automation around these features using Amazon Bedrock Agents. Amazon Bedrock is a fully managed service that offers a choice of high-performing foundation models (FMs) from leading AI companies such as AI21 Labs, Anthropic, Cohere, Meta, Mistral AI, Stability AI, and Amazon through a single API, along with a broad set of capabilities to build generative AI applications with security, privacy, and responsible AI. With Amazon Bedrock Agents, you can orchestrate multi-step processes and integrate with enterprise data using natural language instructions.
In this post, we propose a solution using DigitalDhan, a generative AI-based solution to automate customer onboarding and digital lending. The proposed solution uses Amazon Bedrock Agents to automate services related to KYC verification, credit and risk assessment, and notification. Financial institutions can use this solution to help automate the customer onboarding, KYC verification, credit decisioning, credit underwriting, and notification processes. This post demonstrates how you can gain a competitive advantage using Amazon Bedrock Agents based automation of a complex business process.
Why generative AI is best suited for assistants that support customer journeys
Traditional AI assistants that use rules-based navigation or natural language processing (NLP) based guidance fall short when handling the nuances of complex human conversations. For instance, in a real-world customer conversation, the customer might provide inadequate information (for example, missing documents), ask random or unrelated questions that aren’t part of the predefined flow (for example, asking for loan pre-payment options while verifying the identity documents), natural language inputs (such as using various currency modes, such as representing twenty thousand as “20K” or “20000” or “20,000”). Additionally, rules-based assistants don’t provide additional reasoning and explanations (such as why a loan was denied). Some of the rigid and linear flow-related rules either force customers to start the process over again or the conversation requires human assistance.
Generative AI assistants excel at handling these challenges. With well-crafted instructions and prompts, a generative AI-based assistant can ask for missing details, converse in human-like language, and handle errors gracefully while explaining the reasoning for their actions when required. You can add guardrails to make sure that these assistants don’t deviate from the main topic and provide flexible navigation options that account for real-world complexities. Context-aware assistants also enhance customer engagement by flexibly responding to the various off-the-flow customer queries.
Solution overview
DigitalDhan, the proposed digital lending solution, is powered by Amazon Bedrock Agents. They have developed a solution that fully automates the customer onboarding, KYC verification, and credit underwriting process. The DigitalDhan service provides the following features:
- Customers can understand the step-by-step loan process and the documents required through the solution
- Customers can upload KYC documents such as PAN and Aadhar, which DigitalDhan verifies through automated workflows
- DigitalDhan fully automates the credit underwriting and loan application process
- DigitalDhan notifies the customer about the loan application through email
We have modeled the digital lending process close to a real-world scenario. The high-level steps of the DigitalDhan solution are shown in the following figure.
The key business process steps are:
- The loan applicant initiates the loan application flow by accessing the DigitalDhan solution.
- The loan applicant begins the loan application journey. Sample prompts for the loan application include:
- “What is the process to apply for loan?”
- “I would like to apply for loan.”
- “My name is Adarsh Kumar. PAN is ABCD1234 and email is john_doe@example.org. I need a loan for 150000.”
- The applicant uploads their PAN card.
- The applicant uploads their Aadhar card.
- The DigitalDhan processes each of the natural language prompts. As part of the document verification process, the solution extracts the key details from the uploaded PAN and Aadhar cards such as name, address, date of birth, and so on. The solution then identifies whether the user is an existing customer using the PAN.
- If the user is an existing customer, the solution gets the internal risk score for the customer.
- If the user is a new customer, the solution gets the credit score based on the PAN details.
- The solution uses the internal risk score for an existing customer to check for credit worthiness.
- The solution uses the external credit score for a new customer to check for credit worthiness.
- The credit underwriting process involves credit decisioning based on the credit score and risk score, and calculates the final loan amount for the approved customer.
- The loan application details along with the decision are sent to the customer through email.
Technical solution architecture
The solution primarily uses Amazon Bedrock Agents (to orchestrate the multi-step process), Amazon Textract (to extract data from the PAN and Aadhar cards), and Amazon Comprehend (to identify the entities from the PAN and Aadhar card). The solution architecture is shown in the following figure.
The key solution components of the DigitalDhan solution architecture are:
- A user begins the onboarding process with the DigitalDhan application. They provide various documents (including PAN and Aadhar) and a loan amount as part of the KYC
- After the documents are uploaded, they’re automatically processed using various artificial intelligence and machine learning (AI/ML) services.
- Amazon Textract is used to extract text information from the uploaded documents.
- Amazon Comprehend is used to identify entities such as PAN and Aadhar.
- The credit underwriting flow is powered by Amazon Bedrock Agents.
- The knowledge base contains loan-related documents to respond to loan-related queries.
- The loan handler AWS Lambda function uses the information in the KYC documents to check the credit score and internal risk score. After the credit checks are complete, the function calculates the loan eligibility and processes the loan application.
- The notification Lambda function emails information about the loan application to the customer.
- The Lambda function can be integrated with external credit APIs.
- Amazon Simple Email Service (Amazon SES) is used to notify customers of the status of their loan application.
- The events are logged using Amazon CloudWatch.
Amazon Bedrock Agents deep dive
Because we used Amazon Bedrock Agents heavily in the DigitalDhan solution, let’s look at the overall functioning of Amazon Bedrock Agents. The flow of the various components of Amazon Bedrock Agents is shown in the following figure.
The Amazon Bedrock agents break each task into subtasks, determine the right sequence, and perform actions and knowledge searches. The detailed steps are:
- Processing the loan application is the primary task performed by the Amazon Bedrock agents in the DigitalDhan solution.
- The Amazon Bedrock agents use the user prompts, conversation history, knowledge base, instructions, and action groups to orchestrate the sequence of steps related to loan processing. The Amazon Bedrock agent takes natural language prompts as inputs. The following are the instructions given to the agent:
You are DigitalDhan, an advanced AI lending assistant designed to provide personal loan-related information create loan application. Always ask for relevant information and avoid making assumptions. If you're unsure about something, clearly state "I don't have that information."
Always greet the user by saying the following: Hi there! I am DigitalDhan bot. I can help you with loans over this chat. To apply for a loan, kindly provide your full name, PAN Number, email, and the loan amount."
When a user expresses interest in applying for a loan, follow these steps in order, always ask the user for necessary details:
1. Determine user status: Identify if they're an existing or new customer.
2. User greeting (mandatory, do not skip): After determining user status, welcome returning users using the following format:
Existing customer: Hi {customerName}, I see you are an existing customer. Please upload your PAN for KYC.
New customer: Hi {customerName}, I see you are a new customer. Please upload your PAN and Aadhar for KYC.
3. Call Pan Verification step using the uploaded PAN document
4. Call Aadhaar Verification step using the uploaded Aadhaar document. Request the user to upload their Aadhaar card document for verification.
5. Loan application: Collect all necessary details to create the loan application.
6. If the loan is approved (email will be sent with details):
For existing customers: If the loan officer approves the application, inform the user that their loan application has been approved using following format: Congratulations {customerName}, your loan is sanctioned. Based on your PAN {pan}, your risk score is {riskScore} and your overall credit score is {cibilScore}. I have created your loan and the application ID is {loanId}. The details have been sent to your email.
For new customers: If the loan officer approves the application, inform the user that their loan application has been approved using following format: Congratulations {customerName}, your loan is sanctioned. Based on your PAN {pan} and {aadhar}, your risk score is {riskScore} and your overall credit score is {cibilScore}. I have created your loan and the application ID is {loanId}. The details have been sent to your email.
7. If the loan is rejected ( no emails sent):
For new customers: If the loan officer rejects the application, inform the user that their loan application has been rejected using following format: Hello {customerName}, Based on your PAN {pan} and aadhar {aadhar}, your overall credit score is {cibilScore}. Because of the low credit score, unfortunately your loan application cannot be processed.
For existing customers: If the loan officer rejects the application, inform the user that their loan application has been rejected using following format: Hello {customerName}, Based on your PAN {pan}, your overall credit score is {creditScore}. Because of the low credit score, unfortunately your loan application cannot be processed.
Remember to maintain a friendly, professional tone and prioritize the user's needs and concerns throughout the interaction. Be short and direct in your responses and avoid making assumptions unless specifically requested by the user.
Be short and prompt in responses, do not answer queries beyond the lending domain and respond saying you are a lending assistant
- We configured the agent preprocessing and orchestration instructions to validate and perform the steps in a predefined sequence. The few-shot examples specified during the agent instructions boost the accuracy of the agent performance. Based on the instructions and the API descriptions, the Amazon Bedrock agent creates a logical sequence of steps to complete an action. In the DigitalDhan example, instructions are specified such that the Amazon Bedrock agent creates the following sequence:
- Greet the customer.
- Collect the customer’s name, email, PAN, and loan amount.
- Ask for the PAN card and Aadhar card to read and verify the PAN and Aadhar number.
- Categorize the customer as an existing or new customer based on the verified PAN.
- For an existing customer, calculate the customer internal risk score.
- For a new customer, get the external credit score.
- Use the internal risk score (for existing customers) or credit score (for external customers) for credit underwriting. If the internal risk score is less than 300 or if the credit score is more than 700, sanction the loan amount.
- Email the credit decision to the customer’s email address.
- Action groups define the APIs for performing actions such as creating the loan, checking the user, fetching the risk score, and so on. We described each of the APIs in the OpenAPI schema, which the agent uses to select the most appropriate API to perform the action. Lambda is associated with the action group. The following code is an example of the
create_loan
API. The Amazon Bedrock agent uses the description for the create_loan
API while performing the action. The API schema also specifies customerName
, address
, loanAmt
, PAN
, and riskScore
as required elements for the APIs. Therefore, the corresponding APIs read the PAN number for the customer (verify_pan_card
API), calculate the risk score for the customer (fetch_risk_score
API), and identify the customer’s name and address (verify_aadhar_card
API) before calling the create_loan
API.
"/create_loan":
post:
summary: Create New Loan application
description: Create new loan application for the customer. This API must be
called for each new loan application request after calculating riskscore and
creditScore
operationId: createLoan
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
customerName:
type: string
description: Customer’s Name for creating the loan application
minLength: 3
loanAmt:
type: string
description: Preferred loan amount for the loan application
minLength: 5
pan:
type: string
description: Customer's PAN number for the loan application
minLength: 10
riskScore:
type: string
description: Risk Score of the customer
minLength: 2
creditScore:
type: string
description: Risk Score of the customer
minLength: 3
required:
- customerName
- address
- loanAmt
- pan
- riskScore
- creditScore
responses:
'200':
description: Success
content:
application/json:
schema:
type: object
properties:
loanId:
type: string
description: Identifier for the created loan application
status:
type: string
description: Status of the loan application creation process
- Amazon Bedrock Knowledge Bases provides a cloud-based Retrieval Augmented Generation (RAG) experience to the customer. We have added the documents related to loan processing, the general information, the loan information guide, and the knowledge base. We specified the instructions for when to use the knowledge base. Therefore, during the beginning of a customer journey, when the customer is in the exploration stage, they get responses with how-to instructions and general loan-related information. For instance, if the customer asks “What is the process to apply for a loan?” the Amazon Bedrock agent fetches the relevant step-by-step details from the knowledge base.
- After the required steps are complete, the Amazon Bedrock agent curates the final response to the customer.
Let’s explore an example flow for an existing customer. For this example, we have depicted various actions performed by Amazon Bedrock Agents for an existing customer. First, the customer begins the loan journey by asking exploratory questions. We have depicted one such question—“What is the process to apply for a loan?”—in the following figure. Amazon Bedrock responds to such questions by providing a step-by-step guide fetched from the configured knowledge base.
The customer proceeds to the next step and tries to apply for a loan. The DigitalDhan solution asks for the user details such as the customer name, email address, PAN number, and desired loan amount. After the customer provides those details, the solution asks for the actual PAN card to verify the details, as shown in in the following figure.
When the PAN verification and the risk score checks are complete, the DigitalDhan solution creates a loan application and notifies the customer of the decision through the email, as shown in the following figure.
Prerequisites
This project is built using the AWS Cloud Development Kit (AWS CDK).
For reference, the following versions of node and AWS CDK are used:
- js: v20.16.0
- AWS CDK: 2.143.0
- The command to install a specific version of the AWS CDK is
npm install -g aws-cdk@<X.YY.Z>
Deploy the Solution
Complete the following steps to deploy the solution. For more details, refer to the GitHub repo.
- Clone the repository:
git clone https://github.com/aws-samples/DigitalDhan-GenAI-FSI-LendingSolution-India.git
- Enter the code sample backend directory:
cd DigitalDhan-GenAI-FSI-LendingSolution-India/
- Install packages:
npm install
npm install -g aws-cdk
- Bootstrap AWS CDK resources on the AWS account. If deployed in any AWS Region other than
us-east-1
, the stack might fail because of Lambda layers dependency. You can either comment the layer and deploy in another Region or deploy in us-east-1
.
cdk bootstrap aws://<ACCOUNT_ID>/<REGION>
- You must explicitly enable access to models before they can be used with the Amazon Bedrock service. Follow the steps in Access Amazon Bedrock foundation models to enable access to the models (Anthropic::Claude (Sonnet) and Cohere::Embed English).
- Deploy the sample in your account. The following command will deploy one stack in your account
cdk deploy --all
To protect against unintended changes that might affect your security posture, the AWS CDK prompts you to approve security-related changes before deploying them. You will need to answer yes to fully deploy the stack.
The AWS Identity and Access Management (IAM) role creation in this example is for illustration only. Always provision IAM roles with the least required privileges. The stack deployment takes approximately 10–15 minutes. After the stack is successfully deployed, you can find InsureAssistApiAlbDnsName
in the output section of the stack—this is the application endpoint.
Enable user input
After deployment is complete, enable user input so the agent can prompt the customer to provide addition information if necessary.
- Open the Amazon Bedrock console in the deployed Region and edit the agent.
- Modify the additional settings to enable User Input to allow the agent to prompt for additional information from the user when it doesn’t have enough information to respond to a prompt.
Test the solution
We covered three test scenarios in the solution. The sample data and prompts for the three scenarios can found in the GitHub repo.
- Scenario 1 is an existing customer who will be approved for the requested loan amount
- Scenario 2 is a new customer who will be approved for the requested loan amount
- Scenario 3 is a new customer whose loan application will be denied because of a low credit score
Clean up
To avoid future charges, delete the sample data stored in Amazon Simple Storage Service (Amazon S3) and the stack:
- Remove all data from the S3 bucket.
- Delete the S3 bucket.
- Use the following command to destroy the stack:
cdk destroy
Summary
The proposed digital lending solution discussed in this post onboards a customer by verifying the KYC documents (including the PAN and Aadhar cards) and categorizes the customer as an existing customer or a new customer. For an existing customer, the solution uses an internal risk score, and for a new customer, the solution uses the external credit score.
The solution uses Amazon Bedrock Agents to orchestrate the digital lending processing steps. The documents are processed using Amazon Textract and Amazon Comprehend, after which Amazon Bedrock Agents processes the workflow steps. The customer identification, credit checks, and customer notification are implemented using Lambda.
The solution demonstrates how you can automate a complex business process with the help of Amazon Bedrock Agents and enhance customer engagement through a natural language interface and flexible navigation options.
Test some Amazon Bedrock for banking use cases such as building customer service bots, email classification, and sales assistants by using the powerful FMs and Amazon Bedrock Knowledge Bases that provide a managed RAG experience. Explore using Amazon Bedrock Agents to help orchestrate and automate complex banking processes such as customer onboarding, document verification, digital lending, loan origination, and customer servicing.
About the Authors
Shailesh Shivakumar is a FSI Sr. Solutions Architect with AWS India. He works with financial enterprises such as banks, NBFCs, and trading enterprises to help them design secure cloud services and engages with them to accelerate their cloud journey. He builds demos and proofs of concept to demonstrate the possibilities of AWS Cloud. He leads other initiatives such as customer enablement workshops, AWS demos, cost optimization, and solution assessments to make sure that AWS customers succeed in their cloud journey. Shailesh is part of Machine Learning TFC at AWS, handling the generative AI and machine learning-focused customer scenarios. Security, serverless, containers, and machine learning in the cloud are his key areas of interest.
Reena Manivel is AWS FSI Solutions Architect. She specializes in analytics and works with customers in lending and banking businesses to create secure, scalable, and efficient solutions on AWS. Besides her technical pursuits, she is also a writer and enjoys spending time with her family.