Skip to content

[OPIK-5184] [SDK] feat: Make Prompt and ChatPrompt resilient to backend sync failures#6125

Merged
petrotiurin merged 5 commits intomainfrom
petrotiurin/OPIK-5629-warn-unresolved-entrypoint-params
Apr 9, 2026
Merged

[OPIK-5184] [SDK] feat: Make Prompt and ChatPrompt resilient to backend sync failures#6125
petrotiurin merged 5 commits intomainfrom
petrotiurin/OPIK-5629-warn-unresolved-entrypoint-params

Conversation

@petrotiurin
Copy link
Copy Markdown
Contributor

Details

Prompt() and ChatPrompt() constructors (Python) and createPrompt()/createChatPrompt() (TypeScript) now gracefully handle backend unavailability instead of crashing. When the backend is unreachable, prompts work locally and can be synced later via sync_with_backend() / syncWithBackend().

Key changes across both SDKs:

  • Backend sync errors (API errors, connection errors, timeouts) are caught and logged as warnings instead of propagating
  • Non-API errors (e.g. ValueError, TypeError, PromptTemplateStructureMismatch) still propagate normally
  • Added synced property to check if a prompt was successfully persisted
  • Added public sync_with_backend() / syncWithBackend() method for manual retry
  • Unsynced prompts still support format() and all local operations

Change checklist

  • User facing
  • Documentation update

Issues

  • OPIK-5184

AI-WATERMARK

AI-WATERMARK: yes

  • Tools: Claude Code
  • Model(s): Claude Opus 4.6
  • Scope: full implementation
  • Human verification: code review + unit tests

Testing

Python SDK:

cd sdks/python
python -m pytest tests/unit/api_objects/prompt/test_prompt_sync.py -v  # 14 tests
python -m pytest tests/unit/api_objects/test_opik_client.py::TestOpikClientCreateChatPrompt -v  # 2 tests

All 16 tests pass. Pre-commit hooks (ruff, ruff-format, mypy) pass.

TypeScript SDK:

cd sdks/typescript
npx vitest run tests/unit/client/client-prompts.test.ts  # 31 tests
npx vitest run tests/unit/client/client-chat-prompts.test.ts  # 11 tests

All 42 tests pass. tsc --noEmit passes with zero errors.

Scenarios validated:

  • Prompt created despite API 500, API 503, connection error, timeout (parametrized)
  • sync_with_backend() returns False/false on failure, True/true on success
  • synced property reflects current sync state
  • Non-API errors (ValueError, TypeError) propagate and prevent construction
  • Existing tests for ChatPrompt creation updated for renamed method

Documentation

N/A

🤖 Generated with Claude Code

petrotiurin and others added 2 commits April 8, 2026 11:35
…c failures

Prompts now work locally even when the backend is unreachable. sync_with_backend()
is public, returns bool, exposes a synced property, and only catches API/network errors.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…sync failures

Equivalent to the Python SDK changes: createPrompt/createChatPrompt now
return unsynced instances on API/timeout errors instead of throwing.
Adds synced property, syncWithBackend() method, and requireSynced() guard.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions github-actions bot added python Pull requests that update Python code tests Including test files, or tests related like configuration. typescript *.ts *.tsx Python SDK TypeScript SDK labels Apr 8, 2026
…s, fix test fixtures

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Tests cover OpikApiError, OpikApiTimeoutError, non-API error propagation,
and syncWithBackend delegation for chat prompts.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@petrotiurin petrotiurin marked this pull request as ready for review April 8, 2026 12:23
@petrotiurin petrotiurin requested a review from a team as a code owner April 8, 2026 12:23
@petrotiurin petrotiurin merged commit e496ae9 into main Apr 9, 2026
152 of 153 checks passed
@petrotiurin petrotiurin deleted the petrotiurin/OPIK-5629-warn-unresolved-entrypoint-params branch April 9, 2026 10:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Python SDK python Pull requests that update Python code tests Including test files, or tests related like configuration. TypeScript SDK typescript *.ts *.tsx

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants