API Reference
Kerb provides a comprehensive set of modules for building LLM applications. Each module is designed to be lightweight, modular, and easy to integrate into your existing projects.
Modules:
- Core Module
- Agent Module
- Cache Module
CacheEntryCacheStatsBaseCacheMemoryCacheDiskCacheTieredCacheLLMCachegenerate_cache_key()generate_prompt_key()generate_embedding_key()cached()create_memory_cache()create_disk_cache()create_tiered_cache()create_llm_cache()invalidate_expired_entries()export_cache_stats()estimate_cache_size()
- Chunk Module
- Config Module
ConfigConfigManagerload_config()save_config()ConfigSourceProviderTypeAppConfigModelConfigProviderConfigcreate_config_manager()create_model_config()create_provider_config()get_openai_config()get_anthropic_config()get_google_config()validate_credentials()load_config_from_file()save_config_to_file()get_default_openai_config()get_default_anthropic_config()get_default_google_config()validate_provider_credentials()
- Context Module
ContextItemContextWindowCompressionResultTruncationStrategyCompressionMethodcreate_context_window()truncate_context_window()compress_context()auto_compress_window()create_sliding_window()create_token_sliding_window()create_adaptive_window()deduplicate_context()reorder_context()merge_context_windows()optimize_context_for_query()format_context_window()context_to_messages()extract_context_summary()assign_priorities()priority_by_recency()priority_by_relevance()priority_by_diversity()
- Document Module
DocumentDocumentFormatload_document()load_text()load_markdown()load_json()load_csv()load_xml()load_html()load_pdf()load_docx()detect_format()is_supported_format()load_directory()load_from_url()load_from_url_async()merge_documents()extract_text_from_html()strip_markdown()split_into_sentences()split_into_paragraphs()clean_text()remove_extra_newlines()preprocess_pdf_text()preprocess_html_text()preprocess_markdown()extract_metadata()extract_document_stats()extract_urls()extract_emails()extract_dates()extract_phone_numbers()
- Embedding Module
EmbeddingModelModelBackendembed()embed_batch()embed_async()embed_batch_async()embed_batch_stream()embed_batch_stream_async()LocalEmbedderOpenAIEmbedderSentenceTransformerEmbedderlocal_embed()openai_embed()openai_embed_batch()openai_embed_async()openai_embed_batch_async()sentence_transformer_embed()sentence_transformer_embed_batch()cosine_similarity()euclidean_distance()manhattan_distance()dot_product()batch_similarity()top_k_similar()normalize_vector()vector_magnitude()mean_pooling()weighted_mean_pooling()max_pooling()embedding_dimension()pairwise_similarities()cluster_embeddings()
- Evaluation Module
EvaluationResultComparisonResultBenchmarkResultTestCaseEvaluationMetricJudgmentCriterioncalculate_bleu()calculate_rouge()calculate_meteor()calculate_exact_match()calculate_f1_score()calculate_semantic_similarity()assess_coherence()assess_fluency()assess_faithfulness()assess_answer_relevance()detect_hallucination()llm_as_judge()pairwise_comparison()ab_test()compare_outputs()run_benchmark()benchmark_prompts()calculate_statistics()confidence_interval()
- Fine-Tuning Module
FineTuningProviderDatasetFormatSplitStrategyValidationLevelTrainingExampleTrainingDatasetValidationResultDatasetStatsTrainingConfigprepare_dataset()split_dataset()balance_dataset()deduplicate_dataset()sample_dataset()filter_dataset()to_openai_format()to_anthropic_format()from_csv()from_json()write_jsonl()read_jsonl()validate_dataset()estimate_cost()analyze_dataset()check_data_quality()create_training_config()estimate_training_time()
- Generation Module
generate()generate_stream()generate_batch()generate_async()GeneratorGenerationConfigGenerationResponseStreamChunkUsageLLMProviderModelNameMessageRoleMessageretry_with_exponential_backoff()async_retry_with_exponential_backoff()parse_json_response()validate_response()format_messages()calculate_cost()RateLimiterResponseCacheCostTrackerget_cost_summary()reset_cost_tracking()BaseProviderregister_provider()get_provider()list_providers()OpenAIGeneratorAnthropicGeneratorGoogleGenerator
- Memory Module
- Multimodal Module
MediaTypeImageFormatAudioFormatVideoFormatVisionModelTranscriptionModelEmbeddingModelMultimodalImageInfoAudioInfoVideoInfoTranscriptionResultVisionAnalysisMultiModalContentdetect_media_type()get_mime_type()validate_media_file()calculate_file_checksum()load_image()get_image_info()convert_image_format()image_to_base64()base64_to_image()extract_dominant_colors()calculate_image_hash()analyze_image_with_vision_model()embed_multimodal()compute_multimodal_similarity()get_audio_info()convert_audio_format()transcribe_audio()transcribe_audio_async()extract_audio_from_video()get_video_info()extract_video_frames()create_video_thumbnail()build_multimodal_prompt()build_anthropic_multimodal_content()build_google_multimodal_content()
- Parsing Module
ParseModeValidationLevelParseResultValidationResultextract_json()parse_json()fix_json()extract_json_array()extract_json_object()ensure_json_output()ensure_list_output()ensure_dict_output()validate_json_schema()parse_to_pydantic()pydantic_to_schema()validate_pydantic()pydantic_to_function()format_function_call()format_tool_call()parse_function_call()format_function_result()extract_code_blocks()extract_xml_tag()extract_markdown_sections()extract_list_items()parse_markdown_table()validate_output()retry_parse_with_fixes()clean_llm_output()
- Preprocessing Module
NormalizationLevelLanguageDetectionModeDeduplicationModeContentTypeLanguageResultQualityMetricsNormalizationConfignormalize_text()normalize_whitespace()normalize_unicode()normalize_quotes()normalize_dashes()remove_accents()clean_html()clean_markdown()remove_urls()remove_emails()remove_phone_numbers()remove_special_chars()remove_extra_whitespace()remove_control_chars()strip_punctuation()normalize_case()to_title_case()to_sentence_case()preserve_acronyms()detect_language()detect_language_batch()is_language()filter_by_language()get_supported_languages()deduplicate_exact()deduplicate_fuzzy()deduplicate_semantic()deduplicate_lines()deduplicate_sentences()find_duplicates()compute_text_hash()filter_by_length()filter_by_pattern()filter_profanity()filter_pii()detect_spam()filter_by_quality()filter_non_ascii()classify_content_type()detect_code()detect_sentiment()measure_readability()count_words()count_sentences()count_paragraphs()expand_contractions()standardize_numbers()standardize_dates()extract_entities()segment_sentences()segment_words()preprocess_batch()preprocess_pipeline()truncate_text()split_long_text()
- Prompt Module
render_template()render_template_safe()validate_template()extract_template_variables()PromptVersionPromptRegistrycreate_version()register_prompt()get_prompt()list_versions()compare_versions()select_version()FewShotExampleExampleSelectorcreate_example()select_examples()format_examples()compress_prompt()optimize_whitespace()analyze_prompt()
- Retrieval Module
- Safety Module
SafetyLevelContentCategoryPIITypeToxicityLevelSafetyResultPIIMatchModerationResultGuardrailmoderate_content()check_toxicity()check_sexual_content()check_violence()check_hate_speech()check_self_harm()check_profanity()detect_pii()redact_pii()detect_email()detect_phone()detect_ssn()detect_credit_card()detect_ip_address()detect_url()anonymize_text()detect_prompt_injection()detect_jailbreak()detect_system_prompt_leak()detect_role_confusion()check_input_safety()validate_output()filter_output()check_output_safety()ensure_safe_json()detect_code_injection()create_guardrail()apply_guardrails()check_content_policy()validate_against_rules()sanitize_input()escape_special_chars()validate_url_safety()check_file_upload()detect_data_exfiltration()match_patterns()classify_content()score_content()extract_entities()
- Testing Module
MockBehaviorFixtureFormatMockResponseTestCaseTestResultFixtureDataPromptFixtureResponseFixturePromptTestCaseSnapshotDataPerformanceMetricsCostReportMockLLMMockStreamingLLMcreate_mock_llm()FixtureManagerload_fixtures()save_fixtures()TestDatasetcreate_dataset()load_dataset()assert_response_contains()assert_response_json()assert_response_quality()
- Tokenizer Module
Module Overview
Core
Shared types and interfaces used across all modules.
Agent
Agent orchestration and execution patterns for multi-step reasoning and autonomous task completion.
Cache
Response and embedding caching mechanisms to reduce API costs and improve latency.
Chunk
Text chunking utilities for optimal context window usage and retrieval performance.
Config
Configuration management for models, providers, API keys, and application settings.
Context
Context window management and token budget tracking for LLM conversations.
Document
Document loading and processing utilities for PDFs, web pages, DOCX, and more.
Embedding
Embedding generation with support for multiple providers and similarity search helpers.
Evaluation
Metrics and benchmarking tools for evaluating LLM outputs (BLEU, ROUGE, BERTScore, etc.).
Fine-Tuning
Model fine-tuning utilities and large dataset preparation for training custom models.
Generation
Unified LLM text generation with multi-provider support (OpenAI, Anthropic, Gemini, Cohere).
Memory
Conversation memory and entity tracking for building stateful applications.
Multimodal
Image, audio, and video processing utilities for multimodal LLM applications.
Parsing
Output parsing and validation for JSON, structured data, and function calls.
Preprocessing
Text cleaning, normalization, and preprocessing utilities for LLM inputs.
Prompt
Prompt engineering utilities, templates, and chain-of-thought patterns.
Retrieval
RAG (Retrieval-Augmented Generation) and vector search utilities for semantic retrieval.
Safety
Content moderation, safety filters, and input validation.
Testing
Testing utilities and helpers for LLM outputs and evaluation workflows.
Tokenizer
Token counting and text splitting utilities compatible with any model.