klira 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. klira-0.0.1/LICENSE +164 -0
  2. klira-0.0.1/NOTICE +30 -0
  3. klira-0.0.1/PKG-INFO +346 -0
  4. klira-0.0.1/README.md +317 -0
  5. klira-0.0.1/klira/__init__.py +5 -0
  6. klira-0.0.1/klira/sdk/__init__.py +873 -0
  7. klira-0.0.1/klira/sdk/_di_container.py +497 -0
  8. klira-0.0.1/klira/sdk/_lazy_imports.py +243 -0
  9. klira-0.0.1/klira/sdk/adapters/__init__.py +32 -0
  10. klira-0.0.1/klira/sdk/adapters/agents_adapter.py +350 -0
  11. klira-0.0.1/klira/sdk/adapters/anthropic_adapter.py +679 -0
  12. klira-0.0.1/klira/sdk/adapters/base.py +128 -0
  13. klira-0.0.1/klira/sdk/adapters/crew_ai.py +868 -0
  14. klira-0.0.1/klira/sdk/adapters/framework_adapter.py +63 -0
  15. klira-0.0.1/klira/sdk/adapters/gemini_adapter.py +469 -0
  16. klira-0.0.1/klira/sdk/adapters/guardrail_adapter.py +94 -0
  17. klira-0.0.1/klira/sdk/adapters/langchain.py +691 -0
  18. klira-0.0.1/klira/sdk/adapters/langgraph_adapter.py +749 -0
  19. klira-0.0.1/klira/sdk/adapters/llama_index.py +778 -0
  20. klira-0.0.1/klira/sdk/adapters/llm_base_adapter.py +22 -0
  21. klira-0.0.1/klira/sdk/adapters/ollama_adapter.py +673 -0
  22. klira-0.0.1/klira/sdk/adapters/openai_agents_adapter.py +1062 -0
  23. klira-0.0.1/klira/sdk/adapters/openai_completion_adapter.py +523 -0
  24. klira-0.0.1/klira/sdk/adapters/openai_responses_adapter.py +546 -0
  25. klira-0.0.1/klira/sdk/analytics/__init__.py +632 -0
  26. klira-0.0.1/klira/sdk/analytics/processors.py +1015 -0
  27. klira-0.0.1/klira/sdk/cache/__init__.py +33 -0
  28. klira-0.0.1/klira/sdk/cache/cache_hierarchy.py +583 -0
  29. klira-0.0.1/klira/sdk/cache/redis_adapter.py +466 -0
  30. klira-0.0.1/klira/sdk/client/__init__.py +5 -0
  31. klira-0.0.1/klira/sdk/client/client.py +99 -0
  32. klira-0.0.1/klira/sdk/config.py +346 -0
  33. klira-0.0.1/klira/sdk/decorators/__init__.py +222 -0
  34. klira-0.0.1/klira/sdk/decorators/base.py +384 -0
  35. klira-0.0.1/klira/sdk/decorators/guardrails.py +650 -0
  36. klira-0.0.1/klira/sdk/decorators/mcp_guardrails.py +307 -0
  37. klira-0.0.1/klira/sdk/decorators/policies.py +578 -0
  38. klira-0.0.1/klira/sdk/guardrails/_service_locator.py +235 -0
  39. klira-0.0.1/klira/sdk/guardrails/augmentation.py +22 -0
  40. klira-0.0.1/klira/sdk/guardrails/decision.py +467 -0
  41. klira-0.0.1/klira/sdk/guardrails/default_policies.yaml +599 -0
  42. klira-0.0.1/klira/sdk/guardrails/engine.py +1108 -0
  43. klira-0.0.1/klira/sdk/guardrails/fast_rules.py +672 -0
  44. klira-0.0.1/klira/sdk/guardrails/llm_fallback.py +342 -0
  45. klira-0.0.1/klira/sdk/guardrails/llm_service.py +250 -0
  46. klira-0.0.1/klira/sdk/guardrails/policy_augmentation.py +861 -0
  47. klira-0.0.1/klira/sdk/guardrails/state_manager.py +195 -0
  48. klira-0.0.1/klira/sdk/guardrails/types.py +114 -0
  49. klira-0.0.1/klira/sdk/performance/__init__.py +295 -0
  50. klira-0.0.1/klira/sdk/plugins/__init__.py +311 -0
  51. klira-0.0.1/klira/sdk/plugins/discovery.py +435 -0
  52. klira-0.0.1/klira/sdk/plugins/manager.py +562 -0
  53. klira-0.0.1/klira/sdk/py.typed +1 -0
  54. klira-0.0.1/klira/sdk/streaming/__init__.py +44 -0
  55. klira-0.0.1/klira/sdk/streaming/stream_adapters.py +395 -0
  56. klira-0.0.1/klira/sdk/streaming/stream_cache.py +538 -0
  57. klira-0.0.1/klira/sdk/streaming/stream_guardrails.py +425 -0
  58. klira-0.0.1/klira/sdk/streaming/stream_processor.py +423 -0
  59. klira-0.0.1/klira/sdk/streaming/types.py +298 -0
  60. klira-0.0.1/klira/sdk/telemetry.py +75 -0
  61. klira-0.0.1/klira/sdk/tracing/__init__.py +35 -0
  62. klira-0.0.1/klira/sdk/tracing/tracing.py +234 -0
  63. klira-0.0.1/klira/sdk/types.py +282 -0
  64. klira-0.0.1/klira/sdk/utils/__init__.py +5 -0
  65. klira-0.0.1/klira/sdk/utils/cache_manager.py +243 -0
  66. klira-0.0.1/klira/sdk/utils/error_handler.py +107 -0
  67. klira-0.0.1/klira/sdk/utils/framework_detection.py +646 -0
  68. klira-0.0.1/klira/sdk/utils/framework_registry.py +546 -0
  69. klira-0.0.1/klira/sdk/utils/helpers.py +55 -0
  70. klira-0.0.1/klira/sdk/utils/span_utils.py +64 -0
  71. klira-0.0.1/klira/sdk/utils/type_validator.py +342 -0
  72. klira-0.0.1/klira/version.py +3 -0
  73. klira-0.0.1/pyproject.toml +146 -0
klira-0.0.1/LICENSE ADDED
@@ -0,0 +1,164 @@
1
+ Klira AI SDK License Agreement
2
+ Version 1.0
3
+ Effective Date: August 7, 2025
4
+
5
+ Copyright (c) 2025 Klira AI Technologies. All rights reserved.
6
+
7
+ TERMS AND CONDITIONS
8
+
9
+ 1. DEFINITIONS
10
+ "Software" refers to the Klira AI SDK source code, documentation, and any derivative works.
11
+ "Commercial Use" means any use of the Software (i) in connection with any business activity,
12
+ (ii) in a production environment serving end users, (iii) that generates revenue directly
13
+ or indirectly, (iv) by or for any commercial entity, (v) that provides competitive
14
+ advantage in any commercial context, or (vi) in any organizational context where the
15
+ Software supports business operations, regardless of whether monetary compensation is received.
16
+ "Licensor" refers to Klira AI Technologies and its authorized representatives.
17
+ "API Key" means the unique authentication token issued by Klira AI for accessing the Software
18
+ and associated services.
19
+
20
+ 2. GRANT OF LICENSE
21
+ Subject to the terms of this Agreement, Licensor grants you a personal, non-exclusive,
22
+ non-transferable, non-sublicensable, revocable license to use the Klira AI SDK solely in
23
+ connection with your registered account on the Klira AI platform and for the sole purpose
24
+ of developing integrations that interact with Klira AI's services.
25
+
26
+ This license is granted only upon successful registration and activation using a valid
27
+ API Key issued by Klira AI. Registration requires providing accurate identification information
28
+ and maintaining current contact details. API Keys are non-transferable personal licenses
29
+ that expire according to the terms of your Klira AI subscription. Sharing API Keys or using
30
+ expired/suspended keys constitutes unauthorized use and immediate license termination.
31
+
32
+ 3. LICENSE RESTRICTIONS
33
+ You may not:
34
+ • Use the SDK without a valid API Key obtained directly from Klira AI
35
+ • Use the SDK for any Commercial Use without explicit written permission from Klira AI
36
+ • Use the SDK in a production environment without a paid commercial subscription
37
+ • Copy, reproduce, duplicate, clone, modify, create derivative works, reverse-engineer,
38
+ decompile, disassemble, or otherwise attempt to derive the source code or underlying algorithms
39
+ • Remove, disable, circumvent, or bypass any license validation, telemetry, security features,
40
+ technical protection measures, or authentication mechanisms
41
+ • Redistribute, republish, resell, sublicense, or make available the SDK, in whole or in part,
42
+ to any third party
43
+ • Use the SDK to create competing products or services
44
+ • Extract, isolate, or separate individual components of the SDK for independent use
45
+ • Use automated tools or scripts to access or interact with the SDK beyond normal operation
46
+ • Use the SDK in violation of any applicable laws, export regulations, or sanctions
47
+ • Share, transfer, or disclose your API Key to any third party
48
+
49
+ 4. OWNERSHIP AND INTELLECTUAL PROPERTY
50
+ Klira AI retains all rights, title, and interest in and to the SDK, including all intellectual
51
+ property rights, patents, trademarks, trade secrets, and proprietary information. This
52
+ Agreement does not grant you ownership of any portion of the SDK.
53
+
54
+ Any modifications, enhancements, customizations, or derivative works created using or
55
+ incorporating the SDK shall be deemed work-for-hire owned exclusively by Klira AI. You hereby
56
+ assign all right, title, and interest in such works to Klira AI, including all intellectual
57
+ property rights therein.
58
+
59
+ 5. TECHNICAL PROTECTION MEASURES
60
+ The SDK incorporates technical protection measures including but not limited to license
61
+ validation, usage tracking, API key authentication, telemetry systems, anti-tampering
62
+ mechanisms, and code obfuscation. You acknowledge that:
63
+
64
+ • Circumventing, disabling, modifying, or attempting to bypass these measures constitutes
65
+ a material breach of this Agreement and may violate applicable law including the Digital
66
+ Millennium Copyright Act
67
+ • The SDK may validate your API Key and transmit metadata (e.g., usage statistics, SDK version,
68
+ error reports, system information) to Klira AI servers for license enforcement, security auditing,
69
+ and product improvement
70
+ • Klira AI may implement additional technical protection measures at any time
71
+ • You consent to all telemetry and monitoring activities described herein
72
+
73
+ 6. COMPLIANCE AND AUDIT
74
+ Klira AI reserves the right to audit your use of the SDK through technical means including but
75
+ not limited to telemetry monitoring, usage analytics, periodic compliance verification,
76
+ and on-site inspections (with reasonable notice). You agree to:
77
+
78
+ • Cooperate fully with reasonable audit requests
79
+ • Provide access to systems, records, and personnel as needed for compliance verification
80
+ • Maintain accurate records of SDK usage and API Key management
81
+ • Immediately report any suspected unauthorized use or security breaches
82
+
83
+ 7. TERMINATION
84
+ This license is automatically terminated if you:
85
+ • Use the SDK without a valid API Key or with an expired/suspended key
86
+ • Breach any term of this Agreement
87
+ • Attempt to circumvent any technical enforcement mechanisms
88
+ • Fail to cooperate with compliance audits
89
+ • Use the SDK for Commercial Use without proper authorization
90
+
91
+ Upon termination, you must immediately:
92
+ • Cease all use of the SDK
93
+ • Destroy all copies of the SDK in your possession or control
94
+ • Remove any SDK components from your systems
95
+ • Provide written certification of compliance with these termination obligations
96
+
97
+ Sections 4, 8, 9, 10, 11, 13, and 14 shall survive termination of this Agreement.
98
+
99
+ 8. COMMERCIAL LICENSING
100
+ Commercial Use requires a separate commercial license agreement with Klira AI. Contact
101
+ hello@klira.ai to discuss commercial licensing terms, which may include:
102
+ • Revenue sharing arrangements
103
+ • Volume-based licensing fees
104
+ • Enhanced support and service level agreements
105
+ • Custom terms for enterprise deployments
106
+
107
+ 9. LEGAL REMEDIES AND ENFORCEMENT
108
+ You acknowledge that breach of this Agreement would cause immediate and irreparable harm
109
+ to Klira AI for which monetary damages would be inadequate. Therefore, Klira AI shall be entitled
110
+ to seek:
111
+
112
+ • Immediate injunctive relief and specific performance
113
+ • Temporary and permanent restraining orders
114
+ • Seizure and impoundment of infringing materials
115
+ • Damages including lost profits, statutory damages, and attorneys' fees
116
+ • Any other relief deemed just and proper by a court of competent jurisdiction
117
+
118
+ These remedies are cumulative and in addition to any other rights available at law or equity.
119
+
120
+ 10. WARRANTIES AND DISCLAIMERS
121
+ The SDK is provided "AS IS" without warranty of any kind. Klira AI disclaims all warranties,
122
+ express or implied, including but not limited to implied warranties of merchantability,
123
+ fitness for a particular purpose, non-infringement, and quiet enjoyment.
124
+
125
+ Klira AI does not warrant that the SDK will be uninterrupted, error-free, or secure.
126
+
127
+ 11. LIMITATION OF LIABILITY
128
+ IN NO EVENT SHALL KLIRA AI BE LIABLE FOR ANY INDIRECT, INCIDENTAL, SPECIAL, CONSEQUENTIAL,
129
+ PUNITIVE, OR EXEMPLARY DAMAGES ARISING FROM OR RELATING TO THIS AGREEMENT OR YOUR USE
130
+ OF THE SDK, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
131
+
132
+ KLIRA AI'S TOTAL LIABILITY SHALL NOT EXCEED THE AMOUNT PAID BY YOU FOR THE SDK IN THE
133
+ TWELVE MONTHS PRECEDING THE CLAIM.
134
+
135
+ 12. EXPORT COMPLIANCE
136
+ You acknowledge that the SDK may be subject to export control laws and regulations.
137
+ You agree to comply with all applicable export laws and will not export, re-export,
138
+ or transfer the SDK in violation of such laws.
139
+
140
+ 13. GOVERNING LAW AND JURISDICTION
141
+ This Agreement is governed by and construed in accordance with the laws of the State
142
+ of Delaware, United States, without regard to conflict of laws principles. Any disputes
143
+ arising under this Agreement shall be subject to the exclusive jurisdiction of the
144
+ federal and state courts located in Delaware.
145
+
146
+ 14. GENERAL PROVISIONS
147
+ • This Agreement constitutes the entire agreement between the parties
148
+ • Any modifications must be in writing and signed by both parties
149
+ • If any provision is found unenforceable, the remainder shall remain in full force
150
+ • Waiver of any breach does not constitute waiver of any other breach
151
+ • This Agreement is binding upon successors and assigns
152
+ • Section headings are for convenience only and do not affect interpretation
153
+
154
+ 15. CONTACT INFORMATION
155
+ For licensing questions, commercial inquiries, or technical support:
156
+ Email: hello@klira.ai
157
+ Website: https://klira.ai
158
+
159
+ NOTICE: This software is proprietary and confidential. Unauthorized copying, redistribution,
160
+ modification, reverse engineering, or use without a valid API Key is strictly prohibited
161
+ and may result in civil and criminal penalties under applicable law.
162
+
163
+ BY USING THE KLIRA AI SDK, YOU ACKNOWLEDGE THAT YOU HAVE READ, UNDERSTOOD, AND AGREE TO BE
164
+ BOUND BY THE TERMS OF THIS AGREEMENT.
klira-0.0.1/NOTICE ADDED
@@ -0,0 +1,30 @@
1
+ Klira AI SDK
2
+ Copyright 2025 Klira AI Technologies
3
+ Licensed under the Klira AI SDK License Agreement v1.0
4
+
5
+ PROPRIETARY SOFTWARE - COMMERCIAL USE REQUIRES LICENSE
6
+
7
+ This software requires a valid API key for operation.
8
+ Visit https://klira.ai/ to obtain an API key.
9
+
10
+ This software includes third-party components licensed under Apache License 2.0:
11
+
12
+ 1. Traceloop SDK
13
+ Copyright 2024 Traceloop
14
+ Licensed under the Apache License, Version 2.0
15
+ https://github.com/traceloop/openllmetry
16
+
17
+ 2. OpenTelemetry
18
+ Copyright 2024 OpenTelemetry Authors
19
+ Licensed under the Apache License, Version 2.0
20
+ https://github.com/open-telemetry/opentelemetry-python
21
+
22
+ 3. OpenTelemetry SDK
23
+ Copyright 2024 OpenTelemetry Authors
24
+ Licensed under the Apache License, Version 2.0
25
+ https://github.com/open-telemetry/opentelemetry-python/tree/main/opentelemetry-sdk
26
+
27
+ 4. OpenTelemetry OTLP Exporters
28
+ Copyright 2024 OpenTelemetry Authors
29
+ Licensed under the Apache License, Version 2.0
30
+ https://github.com/open-telemetry/opentelemetry-python/tree/main/exporter/opentelemetry-exporter-otlp
klira-0.0.1/PKG-INFO ADDED
@@ -0,0 +1,346 @@
1
+ Metadata-Version: 2.3
2
+ Name: klira
3
+ Version: 0.0.1
4
+ Summary: Klira AI SDK for LLM observability and policy enforcement
5
+ License: Proprietary
6
+ Keywords: llm,observability,policy,governance,tracing,opentelemetry
7
+ Author: Klira AI Team
8
+ Author-email: hello@getklira.com
9
+ Requires-Python: >=3.10,<4
10
+ Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: Other/Proprietary License
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Programming Language :: Python :: 3.13
18
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
19
+ Requires-Dist: colorama (>=0.4.6)
20
+ Requires-Dist: opentelemetry-api (>=1.28.0)
21
+ Requires-Dist: opentelemetry-exporter-otlp-proto-grpc (>=1.28.0)
22
+ Requires-Dist: opentelemetry-exporter-otlp-proto-http (>=1.28.0)
23
+ Requires-Dist: opentelemetry-sdk (>=1.28.0)
24
+ Requires-Dist: pydantic (>=1)
25
+ Requires-Dist: traceloop-sdk (>=0.38.12)
26
+ Project-URL: Documentation, https://docs.getklira.com
27
+ Project-URL: Repository, https://github.com/kliraai/kliraai-sdk
28
+ Description-Content-Type: text/markdown
29
+
30
+ # Klira SDK: Universal Framework Integration
31
+
32
+ Klira SDK provides a unified approach to adding observability, tracing, and guardrails to your LLM applications, regardless of which framework you use.
33
+
34
+ ## Key Features
35
+
36
+ - **Universal Framework Support**: Works with OpenAI Agents SDK, LangChain, CrewAI, LlamaIndex, or custom agents
37
+ - **Automated Framework Detection**: Automatically detects which framework you're using
38
+ - **Unified Decorators**: One set of decorators that adapt to any framework
39
+ - **Built-in Guardrails**: Apply content policies and safety guardrails to any agent
40
+
41
+ ## Quickstart
42
+
43
+ Install the SDK:
44
+
45
+ ```bash
46
+ pip install klira-sdk
47
+ ```
48
+
49
+ Initialize the SDK:
50
+
51
+ ```python
52
+ from klira.sdk import Klira
53
+
54
+ klira = Klira.init(
55
+ app_name="MyApplication",
56
+ api_key="your-api-key", # Set KLIRA_API_KEY env var instead for better security
57
+ enabled=True
58
+ )
59
+ ```
60
+
61
+ ## Using with Any Framework
62
+
63
+ Klira SDK provides a single, unified set of decorators that automatically adapt to whatever framework you're using.
64
+
65
+ ### Example: OpenAI Agents SDK
66
+
67
+ ```python
68
+ from klira.sdk.decorators import tool, workflow, guardrails
69
+ from agents import Agent, Runner
70
+
71
+ # Create tool function
72
+ @tool(name="weather", organization_id="demo_org", project_id="weather_app")
73
+ def get_weather(city: str) -> str:
74
+ """Get the weather for a city."""
75
+ return f"The weather in {city} is sunny and 75°F."
76
+
77
+ # Create agent
78
+ agent = Agent(
79
+ name="WeatherBot",
80
+ instructions="You are a helpful weather assistant.",
81
+ tools=[get_weather]
82
+ )
83
+
84
+ # Create workflow
85
+ @workflow(name="weather_workflow", organization_id="demo_org", project_id="weather_app")
86
+ @guardrails() # Apply guardrails automatically
87
+ async def run_weather_agent(query: str, conversation_id: str, user_id: str):
88
+ """Run the weather agent with guardrails."""
89
+ result = await Runner.run(agent, query)
90
+ return result.final_output
91
+ ```
92
+
93
+ ### Example: LangChain
94
+
95
+ ```python
96
+ from klira.sdk.decorators import tool, workflow, guardrails
97
+ from langchain.agents import AgentExecutor, create_openai_tools_agent
98
+ from langchain.tools import BaseTool
99
+ from langchain_openai import ChatOpenAI
100
+
101
+ # Create tool
102
+ @tool(name="calculator", organization_id="demo_org", project_id="math_app")
103
+ def calculator(expression: str) -> str:
104
+ """Calculate a math expression."""
105
+ return str(eval(expression))
106
+
107
+ # Create agent
108
+ llm = ChatOpenAI()
109
+ tools = [calculator]
110
+ agent = create_openai_tools_agent(llm, tools, "You are a math assistant.")
111
+ agent_executor = AgentExecutor(agent=agent, tools=tools)
112
+
113
+ # Create workflow
114
+ @workflow(name="math_workflow", organization_id="demo_org", project_id="math_app")
115
+ @guardrails() # Apply guardrails automatically
116
+ def run_math_agent(query: str, conversation_id: str, user_id: str):
117
+ """Run the math agent with guardrails."""
118
+ return agent_executor.invoke({"input": query})["output"]
119
+ ```
120
+
121
+ ## One SDK for All Frameworks
122
+
123
+ The same decorator pattern works across all supported frameworks:
124
+
125
+ - OpenAI Agents SDK
126
+ - LangChain
127
+ - CrewAI
128
+ - LlamaIndex
129
+ - Custom LLM applications
130
+
131
+ ## Built-in Guardrails
132
+
133
+ Apply guardrails to any agent with the `@guardrails()` decorator:
134
+
135
+ ```python
136
+ @guardrails() # Automatic framework detection
137
+ def run_agent(query):
138
+ # Your agent code here
139
+ pass
140
+ ```
141
+
142
+ Or specify the framework explicitly:
143
+
144
+ ```python
145
+ @guardrails(framework="agents_sdk")
146
+ def run_agent(query):
147
+ # Your agent code here
148
+ pass
149
+ ```
150
+
151
+ ## Examples
152
+
153
+ Check out the `examples/` directory for complete examples of using Klira SDK with different frameworks:
154
+
155
+ - `examples/openai_agents_unified_example.py` - OpenAI Agents SDK example
156
+ - `examples/langchain_unified_example.py` - LangChain example
157
+ - `examples/crewai_unified_example.py` - CrewAI example
158
+ - `examples/llama_index_unified_example.py` - LlamaIndex example
159
+
160
+ ## Hierarchical Tracing
161
+
162
+ Klira SDK allows you to track operations at multiple levels:
163
+
164
+ - **Organization**: The top level, representing your company
165
+ - **Project**: A specific project or application
166
+ - **Agent**: An LLM agent that performs tasks
167
+ - **Tool**: A utility function used by an agent
168
+ - **Task**: An individual operation or function
169
+ - **Conversation**: A series of interactions with an LLM
170
+ - **User**: The end-user of your application
171
+
172
+ You can set these contexts using decorators or manually:
173
+
174
+ ```python
175
+ from klira.sdk.tracing import set_organization, set_project, set_hierarchy_context
176
+
177
+ # Set individual contexts
178
+ set_organization("acme_corp")
179
+ set_project("contract_analysis")
180
+
181
+ # Or set the entire hierarchy at once
182
+ set_hierarchy_context(
183
+ organization_id="acme_corp",
184
+ project_id="contract_analysis",
185
+ agent_id="legal_assistant",
186
+ task_id="data_extraction",
187
+ tool_id="legal_search",
188
+ conversation_id="conv_12345",
189
+ user_id="user_6789"
190
+ )
191
+ ```
192
+
193
+ ## Policy Enforcement and Guardrails
194
+
195
+ Klira SDK includes a powerful guardrails system for enforcing company policies:
196
+
197
+ ```python
198
+ from klira.sdk import Klira
199
+
200
+ # Initialize with policies path and optional LLM service
201
+ Klira.init(
202
+ app_name="my_llm_app",
203
+ api_key="your_klira_api_key",
204
+ policies_path="./my_policies", # Optional, defaults to ./guardrails
205
+ llm_service=my_llm_service # Optional, uses DefaultLLMService if not provided
206
+ )
207
+
208
+ # Process a user message
209
+ guardrails = Klira.get_guardrails()
210
+ result = await guardrails.process_message(
211
+ message="Can you help me fire an employee without documentation?",
212
+ context={"conversation_id": "conv_123"}
213
+ )
214
+
215
+ if not result["allowed"]:
216
+ print(f"Message blocked: {result['blocked_reason']}")
217
+ print(f"Violated policies: {result['violated_policies']}")
218
+ else:
219
+ # Continue processing the message
220
+ pass
221
+
222
+ # Augment a system prompt with policy guidelines
223
+ augmented_prompt = await guardrails.augment_system_prompt(
224
+ system_prompt="You are a helpful assistant.",
225
+ context={"matched_policies": [...]}
226
+ )
227
+ ```
228
+
229
+ The guardrails system uses a multi-layered approach:
230
+ 1. **Fast Rules Engine**: Pattern matching for quick policy evaluation
231
+ 2. **Policy Augmentation**: Enhances prompts with policy guidelines
232
+ 3. **LLM Fallback**: For sophisticated policy evaluation in edge cases
233
+
234
+ ## OpenTelemetry Integration
235
+
236
+ Klira SDK uses OpenTelemetry for observability. To send data to your own OpenTelemetry collector:
237
+
238
+ ```python
239
+ # Connect to your OpenTelemetry collector
240
+ Klira.init(
241
+ app_name="my_llm_app",
242
+ opentelemetry_endpoint="http://your-opentelemetry-collector:4318"
243
+ )
244
+
245
+ # Or with environment variables
246
+ # KLIRA_OPENTELEMETRY_ENDPOINT="http://your-opentelemetry-collector:4318"
247
+ ```
248
+
249
+ ## Environment Variables
250
+
251
+ - `KLIRA_API_KEY`: Your Klira AI API key
252
+ - `KLIRA_OPENTELEMETRY_ENDPOINT`: Custom OpenTelemetry collector endpoint
253
+ - `KLIRA_TELEMETRY_ENABLED`: Set to "false" to disable telemetry (default: "true")
254
+ - `KLIRA_TRACE_CONTENT`: Set to "false" to disable content tracing (default: "true")
255
+ - `KLIRA_TRACING_ENABLED`: Set to "false" to disable tracing (default: "true")
256
+ - `KLIRA_METRICS_ENABLED`: Set to "false" to disable metrics (default: "true")
257
+ - `KLIRA_LOGGING_ENABLED`: Set to "true" to enable logging (default: "false")
258
+ - `KLIRA_POLICIES_PATH`: Path to your policy files (default: "./guardrails")
259
+ - `KLIRA_POLICY_ENFORCEMENT`: Set to "false" to disable policy enforcement (default: "true")
260
+
261
+ ## Compliance Reporting
262
+
263
+ The hierarchical tracing features of Klira SDK make it easy to generate compliance reports by:
264
+
265
+ 1. Identifying which organization and project the LLM activity belongs to
266
+ 2. Tracking which agents and tools were used
267
+ 3. Logging the specific tasks that were performed
268
+ 4. Associating activities with specific conversations and users
269
+ 5. Recording policy evaluations and enforcement actions
270
+
271
+ This detailed tracing enables comprehensive audit trails and makes it simple to document compliance with your organization's policies.
272
+
273
+ ## Custom LLM Services
274
+
275
+ You can integrate your preferred LLM provider for policy evaluation:
276
+
277
+ ```python
278
+ from klira.sdk.guardrails.llm_service import OpenAILLMService
279
+ from openai import AsyncOpenAI
280
+
281
+ # Set up OpenAI client
282
+ openai_client = AsyncOpenAI(api_key="your-openai-api-key")
283
+ llm_service = OpenAILLMService(client=openai_client, model="gpt-4o-mini")
284
+
285
+ # Initialize Klira with custom LLM service
286
+ Klira.init(
287
+ app_name="my_llm_app",
288
+ api_key="your_klira_api_key",
289
+ llm_service=llm_service
290
+ )
291
+ ```
292
+
293
+ ## Custom Telemetry
294
+
295
+ To emit Klira AI-specific events and enable richer observability, ensure the SDK is initialized with telemetry enabled (this might involve setting specific environment variables or configuration parameters depending on your setup, e.g., `KLIRA_TELEMETRY=true` or similar if applicable based on `klira/sdk/telemetry.py`'s implementation). Then, you can capture custom events using the `Telemetry` class:
296
+
297
+ ```python
298
+ from klira.sdk.telemetry import Telemetry
299
+
300
+ # Example within your application code where Klira SDK is used
301
+ def my_function():
302
+ # ... some operation ...
303
+
304
+ # Capture a custom event
305
+ Telemetry().capture(
306
+ event_name="my_custom_event",
307
+ properties={"key": "value", "status": "completed"}
308
+ )
309
+
310
+ # ... rest of the function ...
311
+ ```
312
+
313
+ Consult the `klira/sdk/telemetry.py` module for details on its initialization and usage.
314
+
315
+ ## Contributing
316
+
317
+ We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for more information.
318
+
319
+ ## Project Governance
320
+
321
+ Klira SDK follows a meritocratic governance model. For details about our project structure, decision-making process, and community guidelines, please see:
322
+
323
+ - [Project Governance](GOVERNANCE.md) - Overall project structure and decision-making process
324
+ - [Maintainers Guide](MAINTAINERS.md) - Guidelines for project maintainers
325
+ - [Security Policy](SECURITY.md) - Security reporting and handling procedures
326
+ - [Code of Conduct](CODE_OF_CONDUCT.md) - Project's code of conduct
327
+ - [Contributing](CONTRIBUTING.md) - Contributing to Klira AI SDK guidelines
328
+
329
+ ## Third-Party Components
330
+
331
+ This project uses several third-party components that are licensed under the Apache License 2.0:
332
+
333
+ - **Traceloop SDK**: For LLM observability and tracing
334
+ - **OpenTelemetry**: For distributed tracing and metrics
335
+ - **OpenTelemetry SDK**: Core SDK implementation
336
+ - **OpenTelemetry OTLP Exporters**: For exporting telemetry data
337
+
338
+ For detailed attribution and license information, please see the [NOTICE](NOTICE) file included in this package.
339
+
340
+ ## License
341
+
342
+ Proprietary - Klira SDK License Agreement v1.0
343
+
344
+ This software is licensed under the Klira SDK License Agreement. Commercial use requires explicit written permission. Please see the [LICENSE](LICENSE) file for full terms.
345
+
346
+ For licensing inquiries, contact: hello@getklira.com