##Example 1
retriever = db.as_retriever(
search_type=”similarity_score_threshold”,
search_kwargs={“score_threshold”: 0.5}
)
##Example 2
…….
llm_jurassic = Bedrock(
client=bedrock_client,
model_id=”ai21.j2-ultra-v1″,
endpoint_url=”https://bedrock-runtime.” + REGION_NAME + “.amazonaws.com”,
model_kwargs={“temperature”: 0.2, “maxTokens”: 1200, “numResults”: 1}
)
qnachain = ConversationalRetrievalChain.from_llm(
llm=llm_jurassic,
condense_question_llm=llm_jurassic,
retriever=retriever,
return_source_documents=True,
condense_question_prompt=question_generator_chain_prompt,
combine_docs_chain_kwargs={“prompt”: combine_docs_chain_prompt}
)
…….
llm_result = qnachain(input_variables)
…….
if(len(llm_result[‘source_documents’]) > 0):
response_text = llm_result[“answer”].strip()
else:
response_text = “I don’t know, no source documents matched your question”
This vulnerability occurs when an LLM output is accepted without scrutiny, exposing backend systems. Misuse may lead to severe consequences like XSS, CSRF, SSRF, privilege escalation, or remote code execution.
Insecure Output Handling is the result of inadequate validation, sanitation, and management of outputs generated by LLMs before they are sent downstream for further consumption or processing. This vulnerability arises because LLM-generated content can be influenced by user input, effectively granting indirect access to additional functionality.
Potential Impact:
Exploiting Insecure Output Handling can lead to security risks such as XSS and CSRF in web browsers, as well as SSRF, privilege escalation, or remote code execution in back-end systems. This vulnerability can be exacerbated by over-privileged LLM access, susceptibility to indirect prompt injection attacks, and insufficient input validation third-party plugins.
Mitigations:
Utilize a zero-trust approach and treat the LLM as an insider threat.
This occurs when LLM training data is tampered, introducing vulnerabilities or biases that compromise security, effectiveness, or ethical behavior. Sources include Common Crawl, WebText, OpenWebText, & books.
Data poisoning is essentially an ‘integrity attack’ due to its disruptive influence on the fundamental capacity of our AI model to generate precise predictions. Introducing external data increases the risk of training data poisoning due to the limited control that model developers have over it.
Potential Impact:
Poisoned information may result in false, biased or inappropriate content be presented to users or create other risks like performance degradation, downstream software exploitation.
Mitigations:
Attackers cause resource-heavy operations on LLMs, leading to service degradation or high costs. The vulnerability is magnified due to the resource-intensive nature of LLMs and unpredictability of user inputs.
Model Denial of Service is similar to a network-based DoS attack — where repeated or very large requests can overwhelm LLM-based systems.
Potential Impact:
This can result in either completely disabling a service or runaway costs when using AWS services that charge for each request made such as Amazon Bedrock, Amazon Kendra, and Amazon Bedrock Knowledge bases using OpenSearch Serverless (since it could potentially scale the required OCUs).
Mitigations:
from langchain.llms.bedrock import Bedrock
import boto3
bedrock_client=boto3.client(‘bedrock-runtime’)
#print(‘Initalizing Anthropic Claude v2.1’)
llm_anthropic_claude21 = Bedrock(
client=bedrock_client,
model_id=”anthropic.claude-v2:1″,
endpoint_url=”https://bedrock-runtime.” + REGION_NAME + “.amazonaws.com”,
model_kwargs={“temperature”: 0.25, “max_tokens_to_sample”: 1000}
)
from langchain.cache import SQLiteCache
set_llm_cache(SQLiteCache(database_path=”.langchain.db”))