Define a semantic event

Semantic events are events for which the value is assigned by LLM. They can be either Boolean, String, or Number.

First, you need to create a pipeline in Laminar that will assess the event. Proceed to Pipeline Builder documentation to learn more. The LLM tutorial may also come in handy.

Create a pipeline using one or more LLM nodes. Write prompts in them to assess an event.

Example prompt for user sentiment detection.

“Your goal is to detect the sentiment of the user. The user can be happy, neutral, or sad.”

Example BAML structured output:

enum Sentiment {
    Happy
    Neutral
    Sad
}

class SentimentLabel {
    sentiment Sentiment
    reasoning string
}

Trigger a semantic event

To trigger a semantic event, call the evaluate_event function inside instrumented function.

If an event is sent outside of span context, we will have nothing to associate it with, so it won’t be recorded. Make sure to wrap your function with observe.
from lmnr import Laminar as L, observe

L.initialize()

@observe()
def my_function():
    # ...
    L.evaluate_event(
        "my_event_name",
        "my_pipeline_name",
        {"input_node_name": "Is your AI agent working at all???!!!"},
        {"OPENAI_API_KEY": "my_openai_api_key"},
    )
    # ...

evaluate_event function will trigger the background process on Laminar side and the event outcome will be recorded in the event outcome tab.

The semantic event’s timestamp will be set as the time at which it was triggered, unless otherwise specified.

Event metrics

All recorded events are available in the Laminar dashboard and in the events page. Events can also be seen in the traces they are associated with.

Traces of the evaluator pipelines are also available in the traces page.