liveBook · Manning

Prompt

As explained in Spring AI in Action

A prompt is input supplied to a language model to elicit a generated response, potentially including text and image context.

A prompt is input supplied to a language model to elicit a generated response. It can ask a question, provide a document for summarization, request classification or moderation, assess sentiment, or describe an image to generate. section 1.1

Spring AI treats prompts as part of a client abstraction over multiple AI providers. ChatClient builds the request fluently, submits it, and returns generated content without requiring application code to manage provider-specific HTTP details. section 1.1 section 1.1.2

Build a basic prompt in a Spring Boot service by:

  • Injecting ChatClient.Builder and creating a ChatClient. section 1.1.2
  • Calling prompt(), placing application input in user(), and ending with call().content(). section 1.1.2
  • Returning the generated content through a REST endpoint such as POST /ask. section 1.1.2

Prompts can contain separate messages with roles. User messages carry application questions, system messages provide application instructions, assistant messages support multiturn conversations, and tool messages support external actions or context. Provider support varies; Spring AI can fold system text into the user message when necessary. section 3.3

Role-separated board-game prompt

A board-game service can place game-specific instructions and rules in a system prompt, then pass the player’s question as a user message. The fluent call submits both messages and returns the answer. section 3.3

Sentiment-analysis prompt

A sentiment endpoint can instruct the model to score text from -1.0 to +1.0 and explain the score, then return the analyzed text, score, and explanation as structured output. section 11.3

Listing 3.4 Splitting the prompt into distinct user and system messages
@Override
public Answer askQuestion(Question question) {
  var gameRules = gameRulesService.getRulesFor(question.gameTitle());

  var answerText = chatClient.prompt()
      .system(systemSpec -> systemSpec      #1
          .text(promptTemplate)
          .param("gameTitle", question.gameTitle())
          .param("rules", gameRules))
      .user(question.question())             #2
      .call()
      .content();

  return new Answer(question.gameTitle(), answerText);
}

Inspect a complete ChatClient implementation that combines a parameterized system prompt with a user question. section 3.3

How Spring AI in Action covers it

How deep it goes
Explains prompt construction, provider abstraction, message roles, templates, and REST integration, while deferring broader conversations and tool interactions.
Examples
Demonstrates question answering, board-game rules, role-separated messages, sentiment scoring, document summarization, translation, and image-generation descriptions.
What it assumes
Assumes Java, Spring Boot, REST, and an AI-provider API key while introducing prompt construction and provider-independent client access.
What you can do after
Apply it via Spring AI ChatClient to submit user input, add system instructions, and expose generated results through REST services.
How it connects
Connects prompts with language models, ChatClient, system messages, user messages, prompt templates, sentiment analysis, conversations, and tools.

Also explained in

Compare how 50 books explain prompt →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Spring AI in Action. The section links point to the parts of the book it draws on.