liveBook · Manning

Grounding

As explained in Building Reliable AI Systems

A technique for anchoring an AI system's outputs in external information or evidence.

Grounding anchors an AI response in external information rather than relying only on a model’s learned knowledge. It matters when a plausible answer can still be wrong: a legal assistant, for example, might produce a fabricated case citation. Retrieved evidence or trusted API data gives the model something specific to reference, but the resulting answer still needs verification. section 11.6.6 section 1.2.1

Choose the information source and safeguards to fit the task:

  • Use retrieval-augmented generation (RAG) to fetch relevant documents before generating an answer. Cite authoritative sources so claims can be checked. section 3.3 section 11.6.6
  • Use a function call when the answer depends on current data from a trusted API. Let the model interpret the request and phrase the response; let the API supply the facts. section 2.8.3
  • If grounded information is unavailable, return an uncertainty response rather than inventing an answer. Test hallucination-provoking queries and track the grounding defect rate over time. section 11.6.6
  • For high-stakes legal output, verify citations against authoritative databases and require human review. RAG alone does not eliminate fabricated citations. section 1.2.1

Current weather through a function call

A user asks whether it is raining in Seattle. The chatbot calls a weather function for current conditions, then turns the returned data into a natural-language reply. The model handles the conversation; the external API supplies the weather information. section 2.8.3

import json
MODEL = "gpt-5.4-mini"  #1
def get_chat_response(conversation):  #2
    response = openai.chat.completions.create(
        model=MODEL, messages=conversation,
        tools=tools, tool_choice="auto"
    )
        msg = response.choices[0].message 
        conversation.append(msg)
        if msg.tool_calls: #3
            for tc in msg.tool_calls:  #4

            args = json.loads(tc.function.arguments)
            result = get_weather(**args)   #5
            conversation.append({
                "role": "tool",   #6
                "tool_call_id": tc.id,
                "content": result})
        final = openai.chat.completions.create(
            model=MODEL, messages=conversation)   #7
        conversation.append(final.choices[0].message)

conversation = []   #8

while True:
    user_input = input("You: ")   #9
    conversation.append({"role": "user", "content": user_input})  #10
    get_chat_response(conversation)   #11
    print(f"Chatbot: {conversation[-1].content}")   #12

The Python listing shows the tool-call path: send the conversation with available tools, pass the requested arguments to get_weather, add its result as a tool message, and request the final reply. section 2.8.3

Grounding is especially useful where outdated or inaccurate information has serious consequences. Health-care responses can draw on current clinical guidelines; legal responses can draw on current case law and regulations. Traceability adds accountability, not a guarantee of correctness. section 3.3.4 section 1.2.1

How Building Reliable AI Systems covers it

How deep it goes
Outlines retrieval, citations, uncertainty handling, testing, and monitoring, with a function-calling implementation sketch rather than a full verification pipeline.
Examples
Illustrates API-grounded weather replies and high-stakes uses involving clinical guidelines and legal citations.
What it assumes
Assumes familiarity with language-model responses and, for the implementation example, Python API and function-call concepts.
What you can do after
Apply it via RAG or function calls, then test grounded answers and verify high-stakes claims before use.
How it connects
Connects grounding to RAG, hallucinations, function calling, citations, and human review.

Also explained in

Compare how 8 books explain grounding →

Related concepts

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