Key concepts

Event value is known at the code execution time. Events belong to a span. Events are timestamped when your code reports them, unless you explicitly specify a different time.

Value types

The value of the event can be Boolean, String, or Number.

You don’t have to explicitly specify the value type - the value type is inferred based on the first value sent with the event.

For example, if you send value named “is_calculator_tool_used” with value true, the event will be registered with the type Boolean in the current project. Next time, if you send a non-boolean value to “is_calculator_tool_used”, it will be ignored.

Note that the value type is project-specific. Events with the same name can have different types in different projects.

In Laminar’s SDKs, value is optional. If a value is not provided, it will be inferred to be Boolean and set to true. This is useful for events that are just a tag.

Sending regular events

Installation

Install the package from PyPI.

pip install lmnr

Project API key

To get the project API key, go to the Laminar dashboard, click the project settings, and generate a project API key.

Specify the key at Laminar initialization. If not specified, Laminar will look for the key in the LMNR_PROJECT_API_KEY environment variable.

Example: Assertions

Let’s consider an example where you want to assert that LLM response never contains the name of a particular competitor. Each time the response does contain the competitor’s name, you want to record an event.

from lmnr import Laminar as L, observe

L.initialize(project_api_key='<YOUR_PROJECT_API_KEY>')

competitor_name = "The Greatest Hospital in the Bay Area"

@observe()
def generate_response():
    response = openai.chat.completions.create(
        model="gpt-4o",
        messages=[{"role": "user", "content": "<User question>"}],
    )

    if competitor_name in response:
        L.event("contains_competitor_name", True)
        return "Sorry, I can't answer that."
    
    return response
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 the function where event is sent, or one of its parent functions, with observe or with a manual span context.

Other use-cases for events may include:

  • Record if the user’s issue has been resolved by the assistant or not. Use Boolean value type.
  • Track how many times and which tool has been used. Use Boolean value type for each tool call occurrence or Number value type for the total number of tool calls per conversation.
  • Check if the assistant’s response matches regular expressions. Use Boolean value type.

Event metrics

All recorded events are available in the Laminar dashboard and in the events page. In the events page, if you select an event, you can go to the specific trace where it was sent.