Introduction

Enabling LLM continuation rails made our chatbot more adaptable by letting the language model handle anything not covered by your rules. However, this approach has limits: you can’t directly control the prompts sent to the LLM or how it gathers and formats information. For more advanced, context-aware bots, you need greater control. That’s where variables and Natural Language Description (NLD) come in—they let you store and manipulate data, craft precise prompts, and guide the LLM’s output to fit your needs.

In this lesson, we’ll cover how to use variables in Colang 2.0 to store and manage data, and how to leverage Natural Language Description (NLD) to craft precise prompts and control LLM output. You’ll learn about variable assignment, types, and mutability, as well as best practices for extracting and validating structured information from the LLM.

Variables in Colang 2.0: Assignment, Types, and Mutability
Flow Parameters
Global Variables
Natural Language Description (NLD) and the Generation Operator
Defining Flows with NLD Docstrings

The magic doesn't stop here. You can use the generation operator and NLD to define not only variables, but entire flows. You can describe a flow’s intent and expected behavior using a docstring at the top. When you use a standalone ... operator inside the flow, Colang uses the docstring as the LLM prompt.

Example:

flow main
    """You are a helpful assistant who only discusses travel destinations.
    Politely refuse to answer questions on other topics.

    The user's latest question: "{{ question }}"
    Format your response as:

    bot say "<<the reply>>"
    """
    $question = await user said something
    ...

The docstring sets the assistant’s role and response style. The ... operator triggers the LLM to generate the next step using the docstring as guidance.

When using NLD with the generation operator inside a flow, the LLM’s output is interpreted as is by Colang. This means you must instruct the LLM to format its response exactly as Colang expects. For example, if you want the bot to reply to the user, your prompt or docstring should specify:

bot say "<<the reply>>"

This ensures the LLM generates output that Colang can execute directly. If you don’t specify the format, the LLM might return plain text or an unexpected structure, which could cause errors or unintended behavior.

Having a conversation with the LLM through this setup could turn out like this:

> How do I bake a cake?                                                                                         

I'm here to help you with travel destinations! If you're looking for a great place to enjoy some delicious cake,
I can recommend some wonderful cafes or bakeries in various cities. Just let me know where you're interested in!
                                                                                                                
> What to do in Bangkok?

In Bangkok, you can explore the Grand Palace and Wat Phra Kaew, visit Wat Pho to see the Reclining Buddha, take 
a boat ride along the Chao Phraya River, and enjoy shopping at Chatuchak Weekend Market. Don't forget to try the
delicious street food and experience the vibrant nightlife!
Important Notes and Troubleshooting NLD
  • NLD may not always yield the format you want. If the LLM’s output isn’t as expected, clarify your prompt (e.g., “Return a string in single quotes”).
  • Always validate outputs with type-checking functions to ensure correct data types.
  • Be precise in your instructions, especially when you need structured data or a specific response format.
  • Use {$var} inside prompts sent to the LLM with the generation operator (...). This inserts the value of the variable directly into the prompt string.
  • Use {{ var }} inside docstrings at the top of a flow. When the docstring is used as an LLM prompt (e.g., with a standalone ...), {{ var }} is replaced with the value of the variable. This is useful for templating the docstring prompt with dynamic values.
Summary

Variables and NLD in Colang 2.0 give you fine-grained control over data and LLM-driven actions. You can store and manipulate information, extract structured responses, and guide the LLM to generate the exact output your application needs. This enables you to build more capable, adaptable bots. In the next practice, you’ll apply these features to create advanced conversational flows.

Sign up
Join the 1M+ learners on CodeSignal
Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignal