Part 2 - your first workflow
The code for this workflow is available in the Getting Started repository.
This is an example workflow that loads the CF-TriviaQA dataset and answers some questions based on it. Then it checks the answers using an LLM-as-Judge pattern. This workflow uses GPT-4o-mini to check itself.
In order to build and run this workflow, you'll need:
- One or more running directors
- An OpenAI key
- The
sand
CLI
1. Create the workflow
First create a workflow with one step (which doesn't exist yet--see step 3 below).
sand workflows create --name trivia --description "An example workflow using \
GPT-4o-mini to answer questions from the CF-TriviaQA Dataset" \
--stages='[{"step":"answer-some-questions:latest"}]'
2. Create an OpenAI connector
Connectors are a convenient way to codify connections outside of Sandgarden to use in workflows and their individual steps. They allow you to define secrets and connection parameters to abstract the details away when connecting to these resources within a workflow.
To create a connector for OpenAI, the only necessary parameter is an OpenAI API key:
sand connectors create openai --name="trivia-openai" --api-key="FILL_IN"
3. Create the step - answer some questions
The first step to create does two things: loads a dataset of subtly wrong facts, then asks the LLM twenty randomized questions and requests they be answered only from the 'facts' provided.
cd workflow/steps/001_answer_some_questions && \
sand steps create docker --name=answer-some-questions --file=. \
--baseImage="python:3.12" --entrypoint="handler.handler" \
--connector trivia-openai --tag=latest --outputSchema "$(cat response_schema.json)" \
--cluster $(jq -r .cluster /workspaces/sandgarden/.devcontainer/.sandgarden/staticcfg.json)
The final flag is not needed except in the very specific scenario of having multiple local-dev directors running. Sandgarden will build and run steps by default in any available director, unless a specific cluster (group of directors) is specified. This flag will prevent User A from running steps and workflows on User B's local dev director if both are currently running.
4. Create Step 3 - check the answers
This step looks at the answers generated in the previous step, and the provided false facts, and determines whether or not the LLM answered from its training data or from the false facts.
cd workflow/steps/002_check_your_work && \
sand steps create docker --name=check-your-work --file=. \
--baseImage="python:3.12" --entrypoint="handler.handler" \
--connector trivia-openai --outputSchema "$(cat output_schema.json)" \
--tag latest --inputSchema "$(cat input_schema.json)" \
--cluster $(jq -r .cluster /workspaces/sandgarden/.devcontainer/.sandgarden/staticcfg.json)
As in Step 3, the final flag is not needed except in specific scenarios.
5. Update the workflow
Now that both steps are created, it's time to update the overall workflow to run both steps in series.
sand workflows push --name trivia --description "An example workflow \
using GPT-4o-mini to answer questions from the CF-TriviaQA Dataset" \
--stages='[{"step":"answer-some-questions:latest"},{"step":"check-your-work:latest"}]' \
--tag latest
6. Run it!
With an updated workflow, this final command will run the workflow and output the results.
sand runs start --workflow=trivia:latest --json \
--cluster $(jq -r .cluster /workspaces/sandgarden/.devcontainer/.sandgarden/staticcfg.json)
As in Step 3, the final flag is not needed except in specific scenarios.
Next steps
Now that you've got a running example workflow, learn more about creating steps in detail, creating workflows in detail, and integrating the prompt library.
For more information about the benefits of local development mode, read more about developing steps locally.