Creating Your First AI Workflow
Hi everyone. Today I'll be walking you through Dify's 15-minute quick start guide to building your first AI workflow app. Today we'll be building a country infobot using an LLM with one tool. By learning reliable LLM integration into your applications, you'll be able to eventually build, deploy, and scale any idea, no matter how complex. Dify is built for fast prototyping, smooth iteration, and reliable deployment at any level.
Today we'll just be building a pretty simple chatbot that classifies a user's question response directly using an LLM and enhances the response with a country-specific fun fact. The first thing we want to do is create a workflow. I highly suggest you have the Dify guide on the side so you can follow along to the step-by-step tutorial and also have Dify Studio pulled up. So navigate to Dify Studio. It's this button up here. Uh, I'm already at the studio, but your page should say studio. You can just press that. We want to create a workflow from blank. So, let's create from blank. And I'll just name this country info chatbot. Great. Feel free to add your description, but I'm just going to press create. And now we have a workflow. That is awesome.
Configuring the LLM Block & Structured Outputs
This workflow already has some blocks built in. As you can see, we have the start block, the LLM block, and the answer block. However, for simplicity's sake, I'm just going to delete all of these so we can walk through these ourselves.
The first thing that we want to add is an LLM block. You can navigate to this plus button, add node. Press LLM, and you can press anywhere on the screen to drop this LLM block. And as you can see, there are many options for editing and modifying this LLM block to suit your fancy. So an LLM block essentially sends a prompt to a large language model to generate a response based on the user's input. It abstracts away the complexity of API calls, rates, limits, and infrastructure, so you can just focus on designing logic. Where does it get the user's input? It gets it from start block. So the first thing that you need to do is connect the start block to the LLM block, so the LLM block is able to receive information from the start block. These here in the start block are called variables. It will be able to be accessed by every block following the start block in the workflow. So now that we have that, we can choose a model for what we want to use as our LLM. So you can use the default model. Mine is um DeepSeek AI V3, but yours should have a default model as well. And then let's paste into the prompt system this prompt for our chatbot.
So just copy and we could just paste that right there. I'm just going to paste it without formatting. Great. However, the first thing you notice is that this is a variable that the prompt is trying to reference. The issue with variables is that you will have to enter them manually. So that we just press this bracket. And what we want is the system query. This is the variable being taken from the start block. So instead of copy and pasting it, we just have to delete it and put in the actual variable because when we copy and paste, the prompt does not process it as a variable. So just keep that in mind. The next thing we want to do is enable structured outputs. So let's just toggle this button on in output variables. And great. This will essentially allow us to easily control what LLM we will return and ensure consistent machine-readable outputs for downstream use in precise data extraction or conditional logic.
So, we toggled this on and we'll press configure here and import from JSON, this button up here. We'll just copy and paste this for convenience, but this is essentially what we want our LLM to return, these variables.
Submit. And now we have these three outputs within this block. And we'll just save this here. Great. That's perfect.
We're pretty much done with this LLM block. You can give it a name. We'll say um uh country LLM. Feel free to name it anything you want, but this is typically just for organizational purposes.
Adding Custom Logic with a Code Block
The next block is the code block where we're going to get a fun fact. So, what we want to do is we want to add a code block. If you again go to the add node and under transform there's a code block. I'm just going to plop it right here. And now we have a code block.
The code block executes custom logic using code. It lets you inject code exactly where you need it within a visual workflow, saving you from having to wire up an entire backend. So after creating the code block, we're going to change the input variable to what we want the code block to take in. Now, what we want the code block to take in is actually something that the country LLM's block spits out. So, in order to actually get that variable, we're going to have to connect these two and that'll be part of our workflow. As you can see, go from start to the LLM block to the code block. Great. Now, we have those connected. We only really need one input variable, so I'll just be working with one. And the variable that we want is country. I'm going to name this variable country and set that variable to be the output from the country LLM.
So if you go to structured outputs, which is what we did earlier, you can see that there's a country string that we can connect to be the variable this code block takes in. This is directly from the output that we wanted the LLM to give us when it ran. So, we connect that and now the variable country within this code block will stand for the country that the LLM found within the prompt.
Great. Now, let's just copy and paste this into Python. This is just the code for having our um our fun fact being taken as the fun fact of the country variable. Example, if this country variable had Japan, the fun fact returned would be "Japan has more than five million vending machines." Pretty straightforward. And just the output variable, we can change the name so we can reference it later on in the workflow. I'm just going to change it to fun fact because that's exactly what it is. Um, just have a better label for that. Okay, great. Now we're pretty much done with the code block.
Using the Answer Block to Finalize Output
The last thing we need is the answer block, which essentially just ties all of this together. So, let's again go to add node and find answer block, which should be right up here.
Perfect. Now, we have our answer block. Do not forget we're taking our answers from the LLM and from the code. So, we're just going to connect that so we're able to access all the variables.
Great.
And we're just going to press the answer block. We're going to paste into the answer block the question, answer, and fun fact that we want returned. So this is what the return is going to look like. These again are variables. So what do we want to do? We want to rewrite them to be the actual variables and have them processed the correct way. So we want to reiterate the question from the LLM. Want to reiterate the answer from the LLM. Go to structured outputs answer. And also reiterate the fun fact which is going to be from our code block. So it's right up here. And as you can see the variables are all separated by which block they're from. So code block, country LLM block, and start block. You can find each block's variables under there.
And now that is pretty much the end of our workflow, which is great.
Testing the Workflow and Conclusion
This is what our our answer bot is going to return. But the next thing that we want to do is just test our workflow. So let's see how exactly it previews.
You can see that there's a chatbot and let's... what if we ask what is the capital of France?
Does this work correctly? It's following our workflow process. It's going through the country LLM which is getting the information. And yeah, it seems to be working pretty well. We have our "what is the capital of France". We have Paris being the capital of France. And we have France, the fun fact for France being "France is the most visited country in the world." And our bot seems to be working as expected. So we seem to have completed the bot itself. And this guide really just shows how to integrate the large language models reliably without reinventing infrastructure. With our visual workspace, we're able to build faster and adopt clean production-ready architecture for LLM-powered apps. Thank you so much for following along.