Regular event

Regular events are events for which the value is known at the code execution time. Just like semantic events, they belong to a span.

Regular 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 to 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. Similarly named events can have different types in different projects.

In Laminar’s SDKs, value is optional. If 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 Car Dealership 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 regular 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.