Foundations
Completions are the basic unit of response with an LLM. Given instructions, context, and optionally embedded resources via a prompt, a completion is the response that is generated by the large language model. Withinre-factor, completions can be generated in two formats: text and object. The text format is a human-readable string that can be used for human consumption. The object format is a JSON object that can be used for programmatic access and can be constrained using JSONSchema.
Structure
Fields
The unique identifier for the runnable. This is created automatically by re-factor.
The type of the runnable. For a completion, this should be
"completion".The name of the runnable. This is a human-readable label that helps you identify and manage runnables in your system.
A description of the runnable’s purpose and intended use. This can provide additional context to users and help them understand the purpose and functionality of the runnable.
The prompt template for the completion. This is a string that can contain placeholders for dynamic values and can be used to generate the final prompt text.See the
CompletionPrompt type for this object’s structure.An array of resources that are expected to be embedded into the prompt at runtime. Each resource has a name, type, mime types, description, and optional metadata.Array items must be of type
Resource. This field is optional if the prompt does not require embedded resources.An array of LLM configurations that are exposed within the prompt. Each LLM configuration has a name, provider, model, and optional metadata.Array items must be of type
LLMConfiguration. At least one LLM configuration with default: true must be defined. Exactly one LLM configuration can have default: true.Features
Template Variables
Template variables make your completion runnables dynamic and reusable. You can define variables using the{{ variable_name }} syntax, which can be replaced with actual values when the completion is run. This is particularly useful for creating completion runnables that can be used across different contexts or with different inputs.
Resource Embedding
Resources can be seamlessly transformed and embedded into your prompts using our resources system. This allows you to reference external data, documents, or other content directly within your completion prompts. The LLM will have access to this information during its response generation. For example, assuming we have a Word document resource defined with the namedocument, we can embed it as a PDF into our prompt user message as follows:
Versioning
As you modify your completion runnables in re-factor, they are automatically versioned and previous versions are available in a prompt history, allowing you to:- Track changes over time
- Roll back to previous versions if needed
- Compare performance across different versions
Multiple Generations
It’s often advantageous to use multiple LLM generations in pursuit of a correct answer. With re-factor, you can define a script consisting of multiplerole: "assistant" messages that will be executed in sequence.
Example
Best Practices
When creating prompts in re-factor:- Provide as much detail as possible in your system message
- Use template variables for dynamic elements
- Version your prompts appropriately
- Test prompts across different scenarios
- Document expected inputs and outputs
- Consider resource limitations and costs

