Skip to main content

Overview

Functions are the core of Simforge. Each function defines:
  • Inputs: The data your function accepts
  • Outputs: The structured data your function returns
  • Prompt: The instructions for the LLM
  • Provider: Which LLM to use (OpenAI, Anthropic, etc.)

Creating a Function

  1. Navigate to Functions in the sidebar
  2. Click Create Function
  3. Enter a name for your function (e.g., ExtractName)
  4. Define your function using BAML syntax

Example Function

class NameOutput {
  firstName string
  lastName string
}

function ExtractName(text: string) -> NameOutput {
  client "openai/gpt-4o"
  prompt #"
    Extract the first and last name from the following text:

    {{ text }}

    Return the name as JSON.
  "#
}

Function Editor

The function editor provides:
  • Syntax Highlighting: BAML syntax is highlighted for readability
  • Error Checking: Syntax errors are shown inline
  • Auto-save: Changes are saved automatically as drafts
  • Version History: View and restore previous versions

Editor Tabs

TabDescription
EditorWrite and edit your BAML code
TestRun your function with sample inputs
TracesView execution history for this function
VersionsBrowse and restore previous versions

Testing Functions

Test your function directly in the portal:
  1. Open a function
  2. Click the Test tab
  3. Enter input values in the form
  4. Click Run
  5. View the output and execution details

Test Inputs

Enter test inputs as JSON or use the form fields:
{
  "text": "My name is John Doe and I work at Acme Corp."
}

Versioning

Every time you save a function, a new version is created:
  • Draft: Unsaved changes (not deployed)
  • Published: The active version used by the SDK
  • Previous Versions: Historical versions you can restore

Publishing Changes

  1. Make changes in the editor
  2. Click Save to create a draft
  3. Click Publish to make the version active

Restoring a Version

  1. Open the Versions tab
  2. Find the version you want to restore
  3. Click Restore
  4. The version is copied to a new draft
  5. Review and publish when ready

BAML Syntax

Functions are defined using BAML. Here are the key concepts:

Classes

Define structured output types:
class Person {
  firstName string
  lastName string
  age int?  // optional field
  email string?
}

Enums

Define categorical outputs:
enum Sentiment {
  POSITIVE
  NEGATIVE
  NEUTRAL
}

Functions

Define the function signature and prompt:
function ClassifySentiment(text: string) -> Sentiment {
  client "openai/gpt-4o"
  prompt #"
    Classify the sentiment of the following text as POSITIVE, NEGATIVE, or NEUTRAL:

    {{ text }}
  "#
}

Clients

Configure which LLM provider to use:
client "openai/gpt-4o"        // OpenAI GPT-4o
client "anthropic/claude-3"    // Anthropic Claude 3
client "openai/gpt-3.5-turbo" // OpenAI GPT-3.5 Turbo

Best Practices

  • Descriptive Names: Use clear, descriptive function names like ExtractInvoiceData instead of Extract
  • Typed Outputs: Always define a class for your output to ensure type safety
  • Clear Prompts: Write clear, specific prompts with examples when needed
  • Test Thoroughly: Test with various inputs before publishing
  • Version Control: Use meaningful changes between versions