# Safeguarding LLM Output in Spring AI

DevFeed: [Safeguarding LLM Output in Spring AI](<https://devfeed.tech/articles/safeguarding-llm-output-in-spring-ai-89790.md>)

Original publisher: [Read original article](<https://www.baeldung.com/spring-ai-safeguarding-llm-output>)

Author: Yadier Betancourt

Published: 2026-10-18T17:55:03Z

Content type: tutorial

Language: en

Sources: [Baeldung](<https://devfeed.tech/sources/baeldung.md>)

Topics: [Spring AI](<https://devfeed.tech/topics/spring-ai.md>), [Large Language Model](<https://devfeed.tech/topics/llm.md>), [Spring Framework](<https://devfeed.tech/topics/spring-framework.md>), [LLM security](<https://devfeed.tech/topics/llm-security.md>), [Spring MVC](<https://devfeed.tech/topics/spring-mvc.md>), [console](<https://devfeed.tech/topics/console.md>), [Maven](<https://devfeed.tech/topics/maven.md>)

Tags: [ai](<https://devfeed.tech/tags/ai.md>), [api](<https://devfeed.tech/tags/api.md>), [artificial-intelligence](<https://devfeed.tech/tags/artificial-intelligence.md>), [artificial-intelligence-spring-ai-chatclient](<https://devfeed.tech/tags/artificial-intelligence-spring-ai-chatclient.md>), [developer](<https://devfeed.tech/tags/developer.md>), [gemini](<https://devfeed.tech/tags/gemini.md>), [gemini-api](<https://devfeed.tech/tags/gemini-api.md>), [google](<https://devfeed.tech/tags/google.md>), [guardrail](<https://devfeed.tech/tags/guardrail.md>), [guards](<https://devfeed.tech/tags/guards.md>), [implementing](<https://devfeed.tech/tags/implementing.md>), [llm](<https://devfeed.tech/tags/llm.md>), [popular](<https://devfeed.tech/tags/popular.md>), [spring](<https://devfeed.tech/tags/spring.md>), [spring-ai](<https://devfeed.tech/tags/spring-ai.md>), [spring-ai-chatclient](<https://devfeed.tech/tags/spring-ai-chatclient.md>)

## AI overview

This tutorial shows how to add an output guard to a Spring AI ChatClient. It builds a custom advisor that checks model responses for sensitive terms and replaces matching answers, complementing Spring AI's input guard. The article explains the substring matching limitations and notes that streamed responses bypass this call-only guard.

## Source excerpt

Learn to create a custom advisor that inspects the model's response before Spring AI ChatClient hands it back to the user. The post Safeguarding LLM Output in Spring AI first appeared on Baeldung.