Course contentsShow
← AI Engineering
Lesson 182 of 1,8865. Advanced Prompting TechniquesFree lesson

Parsing Actions from Model Output

Extracting structured action commands from free-form model responses for execution.

Parsing Actions from Model Output

What You'll Learn

You'll learn how to reliably extract structured action commands from the free-form text that language models generate, enabling your AI system to actually do things.

The Core Challenge

When a model uses ReAct prompting (Reasoning + Acting), it generates thoughts and proposes actions in natural language. But your code can't execute phrases like "I should search for..." or "Let me calculate..." — you need to extract the actual action name and parameters in a format your system understands.

Think of it like parsing voice commands: when someone says "Alexa, play jazz music," the system must extract action=play and parameter=jazz music from that sentence.

How Parsing Works

You typically guide the model to use specific markers or formats in its output:

Pattern 1: Delimited Actions

Action: search
Action Input: "weather in Paris"

Pattern 2: JSON-like Structure

{"action": "calculator", "input": "15 * 42"}

Your parsing code then:

  1. Searches for the action delimiter or pattern
  2. Extracts the action name
  3. Extracts the parameters/input
  4. Validates the action exists in your allowed action space
  5. Returns a structured object your code can execute

Common Pitfalls

  • Models sometimes add extra text before/after the action
  • Formatting may be inconsistent (extra spaces, capitalization)
  • Action parameters might be malformed
  • The model might propose invalid actions not in your action space

Your parser must be robust — use regex, string matching, or even a second LLM call to extract structured data from messy output.

Key Takeaway: Parsing transforms unstructured model responses into executable commands by extracting action names and parameters using delimiters, patterns, and validation against your defined action space.