{"id":227195,"date":"2024-06-02T02:36:50","date_gmt":"2024-06-02T02:36:50","guid":{"rendered":"https:\/\/michigandigitalnews.com\/index.php\/2024\/06\/02\/enhancing-llm-application-safety-with-langchain-templates-and-nvidia-nemo-guardrails\/"},"modified":"2025-06-25T17:18:07","modified_gmt":"2025-06-25T17:18:07","slug":"enhancing-llm-application-safety-with-langchain-templates-and-nvidia-nemo-guardrails","status":"publish","type":"post","link":"https:\/\/michigandigitalnews.com\/index.php\/2024\/06\/02\/enhancing-llm-application-safety-with-langchain-templates-and-nvidia-nemo-guardrails\/","title":{"rendered":"Enhancing LLM Application Safety with LangChain Templates and NVIDIA NeMo Guardrails"},"content":{"rendered":"<p> [ad_1]<br \/>\n<\/p>\n<div>\n<figure class=\"figure mt-2\">&#13;<br \/>\n                        <a href=\"https:\/\/image.blockchain.news:443\/features\/D8E08E86F8EDBDDCD68414CF49BDD8B1401B11A69515DFF98E6B2B03EE9CF9D7.jpg\" data-glightbox=\"\" data-gallery=\"image-popup\">&#13;<br \/>\n                            <img decoding=\"async\" class=\"rounded\" src=\"https:\/\/image.blockchain.news:443\/features\/D8E08E86F8EDBDDCD68414CF49BDD8B1401B11A69515DFF98E6B2B03EE9CF9D7.jpg\" alt=\"Enhancing LLM Application Safety with LangChain Templates and NVIDIA NeMo Guardrails\"\/>&#13;<br \/>\n&#13;<br \/>\n                        <\/a>&#13;<br \/>\n                    <\/figure>\n<p>Developers seeking to deploy large language model (LLM) applications more safely and quickly now have a robust solution with LangChain Templates and NVIDIA NeMo Guardrails, according to NVIDIA Technical Blog.<\/p>\n<h2>Benefits of Integrating NeMo Guardrails with LangChain Templates<\/h2>\n<p>LangChain Templates offer developers a new way to create, share, maintain, download, and customize LLM-based agents and chains. These templates enable the swift creation of production-ready applications, leveraging FastAPI for seamless API development in Python. NVIDIA NeMo Guardrails can be integrated into these templates to provide content moderation, enhanced security, and evaluation of LLM responses.<\/p>\n<p>As generative AI continues to evolve, integrating guardrails ensures that LLMs used in enterprise applications remain accurate, secure, and contextually relevant. The NeMo Guardrails platform provides programmable rules and runtime integration to control user inputs before engaging with the LLM and to validate the final LLM output.<\/p>\n<h2>Setting Up the Use Case<\/h2>\n<p>To demonstrate the integration, the blog post explores a Retrieval-Augmented Generation (RAG) use case using an existing LangChain template. The process involves downloading the template, modifying it to suit the specific use case, and then deploying the application with added guardrails to ensure security and accuracy.<\/p>\n<p>LLM guardrails help minimize hallucinations and keep data secure by implementing input and output self-check rails that mask sensitive data or rephrase user inputs. For example, dialog rails can influence how LLMs respond, and retrieval rails can mask sensitive data in RAG applications.<\/p>\n<h2>Downloading and Customizing the LangChain Template<\/h2>\n<p>To begin, developers need to install the LangChain CLI and the LangChain NVIDIA AI Foundation Endpoints package. The template can be downloaded and customized by creating a new application project:<\/p>\n<pre><code>pip install -U langchain-cli&#13;\npip install -U langchain_nvidia_aiplay&#13;\nlangchain app nvidia_rag_guardrails --package nvidia-rag-canonical<\/code><\/pre>\n<p>The downloaded template sets up an ingestion pipeline into a Milvus vector database. In this example, the dataset contains sensitive information regarding Social Security Benefits, making guardrail integration crucial for secure responses.<\/p>\n<h2>Integrating NeMo Guardrails<\/h2>\n<p>To integrate NeMo Guardrails, developers need to create a directory named <strong>guardrails<\/strong> and configure the necessary files such as <code>config.yml<\/code>, <code>disallowed.co<\/code>, <code>general.co<\/code>, and <code>prompts.yml<\/code>. These configurations define the guardrail flows that control the chatbot&#8217;s behavior and ensure it adheres to predefined rules.<\/p>\n<p>For example, a disallowed flow might prevent the chatbot from responding to misinformation, while a general flow might define acceptable topics. Self-checks for user inputs and LLM outputs are also implemented to prevent cybersecurity attacks like prompt injection.<\/p>\n<h2>Activating and Using the Template<\/h2>\n<p>To activate the guardrails, developers need to include the configurations in the <code>config.yml<\/code> file and set up the server for API access. The following code snippets show how to integrate the guardrails and set up the server:<\/p>\n<pre><code>from nvidia_guardrails_with_RAG import chain_with_guardrails as nvidia_guardrails_with_RAG_chain&#13;\nadd_routes(app, nvidia_guardrails_with_RAG_chain, path=\"\/nvidia-guardrails-with-RAG\")<\/code><\/pre>\n<pre><code>from nvidia_guardrails_with_RAG import ingest as nvidia_guardrails_ingest&#13;\nadd_routes(app, nvidia_guardrails_ingest, path=\"\/nvidia-rag-ingest\")<\/code><\/pre>\n<p>Developers can then spin up the LangServe instance with the command:<\/p>\n<pre><code>langchain serve<\/code><\/pre>\n<p>An example of a secure LLM interaction might look like this:<\/p>\n<pre><code>\"Question\": \"How many Americans receive Social Security Benefits?\" &#13;\n\"Answer\": \"According to the Social Security Administration, about 65 million Americans receive Social Security benefits.\"<\/code><\/pre>\n<h2>Conclusion<\/h2>\n<p>This integration of NeMo Guardrails with LangChain Templates demonstrates a robust approach to creating safer LLM applications. By adding security measures and ensuring accurate responses, developers can build trustworthy and secure AI applications.<\/p>\n<p><span><i>Image source: Shutterstock<\/i><\/span>                    <!-- Divider --><\/p>\n<p>. . .<\/p>\n<h4>Tags<\/h4>\n<p>                    <!-- Divider --><\/p>\n<p>                    <!-- Author info START --><\/p>\n<p>                    <!-- Author info END --><br \/>\n                    <!-- Divider -->\n                <\/div>\n<p>[ad_2]<br \/>\n<br \/><a href=\"https:\/\/blockchain.news\/news\/enhancing-llm-application-safety\">Source link <\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>[ad_1] &#13; &#13; &#13; &#13; &#13; Developers seeking to deploy large language model (LLM) applications more safely and quickly now have a robust solution with<\/p>\n","protected":false},"author":1,"featured_media":227196,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[171],"tags":[],"_links":{"self":[{"href":"https:\/\/michigandigitalnews.com\/index.php\/wp-json\/wp\/v2\/posts\/227195"}],"collection":[{"href":"https:\/\/michigandigitalnews.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/michigandigitalnews.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/michigandigitalnews.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/michigandigitalnews.com\/index.php\/wp-json\/wp\/v2\/comments?post=227195"}],"version-history":[{"count":0,"href":"https:\/\/michigandigitalnews.com\/index.php\/wp-json\/wp\/v2\/posts\/227195\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/michigandigitalnews.com\/index.php\/wp-json\/wp\/v2\/media\/227196"}],"wp:attachment":[{"href":"https:\/\/michigandigitalnews.com\/index.php\/wp-json\/wp\/v2\/media?parent=227195"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/michigandigitalnews.com\/index.php\/wp-json\/wp\/v2\/categories?post=227195"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/michigandigitalnews.com\/index.php\/wp-json\/wp\/v2\/tags?post=227195"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}