liveBook · Manning

Prompt

As explained in Build Python Web Apps with Streamlit

A prompt is an input supplied to a language model, typically consisting of one or more conversational messages.

A prompt is the input you send to a large language model to get a response. For a chat request, it is a list of messages. Each message has a role identifying its speaker and content containing its text. A user message asks for something; an optional system message sets context or instructions; assistant messages represent model responses. section 9.2.3 section 9.2.4

>>> messages = [
...     {'role': 'system', 'content': 'You are a helpful programming assistant'},
...     {'role': 'user', 'content': 'Explain what Streamlit is in 10 words or fewer'}
... ]

This small Python prompt pairs a system instruction with a specific user request. The order lets the model receive its context before the question. section 9.2.3

Send the message list to a text-generation endpoint and read the returned response. In an app, a helper can assemble the list from a user message and an optional system message, keeping prompt construction separate from the API call. section 9.2.3 section 9.2.4

Keep a trivia game fresh

A question-generation prompt can tell the model to act as a quizmaster, request a new category and topic, and include questions already asked. The app fills in those questions and a changing seed before each request. Temperature and top_p are also passed to the model to help vary the results; the prompt states the desired behavior rather than guaranteeing uniqueness. section 9.6.2

For a customer-support chatbot, a base system message can identify the support role and instruct the model to refuse unrelated requests. In a LangGraph workflow, place that system message before the conversation messages sent to the model. This gives each request the same intended context without replacing the user’s question. section 10.4.1 section 10.4.2

sys_msg = SystemMessage(content=state["sys_msg_text"])
messages_to_send = [sys_msg] + state["messages"]
ai_response_message = self.llm.invoke(messages_to_send)

The graph constructs a SystemMessage, puts it first, then invokes the model with the resulting message list. section 10.4.2

How Build Python Web Apps with Streamlit covers it

How deep it goes
Defines prompts as role-and-content messages and shows their construction, API submission, revision, and placement in a graph.
Examples
Uses a ten-word Streamlit explanation, a multi-question trivia game, and an on-topic customer-support chatbot.
What it assumes
Starts with Python message lists and dictionaries; API calls require an OpenAI client and API key.
What you can do after
Apply it via the OpenAI Python client or LangGraph to send messages and set task-specific context for an LLM.
How it connects
Connects prompts to chat completions, system messages, conversation state, and LangGraph workflows.

Also explained in

Compare how 50 books explain prompt →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build Python Web Apps with Streamlit. The section links point to the parts of the book it draws on.