Skip to main content

Model-specific prompt optimization. Your prompts, upgraded.

Project description

Refrase

Your prompts, upgraded.

PyPI npm License: MIT Tests

Refrase optimizes your AI prompts for specific models using research-backed, model-specific formatting rules. No LLM required — it's deterministic and instant.

Why?

Most developers write one prompt and hope it works on every model. But models were trained on different data with different RLHF processes. Claude works best with XML tags. Qwen3 needs /think prefixes. Mistral's Magistral emits [TOOL_CALLS] markers that break JSON parsing. Refrase handles all of this automatically.

Quick Start

Python

pip install refrase
import refrase

result = refrase.adapt(
    "You are a helpful data analyst. Extract all key metrics from the report.",
    model="claude-sonnet",
    task="extraction",
)

print(result.system)
# <role>
# You are a helpful data analyst.
# </role>
#
# <instructions>
# Extract all key metrics from the report.
# </instructions>
#
# <output_format>
# Return structured output matching the schema.
# </output_format>

print(result.changes)
# [Change(rule='xml-structure', description='Restructured prompt with XML tags', ...)]

TypeScript

npm install refrase
import { adapt } from "refrase";

const result = adapt({
  prompt: "You are a helpful data analyst. Extract all key metrics.",
  model: "claude-sonnet",
  task: "extraction",
});

console.log(result.system);
console.log(result.changes);

Before / After

Model Before After
Claude Sonnet Plain text prompt XML-tagged <role>, <instructions>, <output_format>
Qwen3 32B No thinking directive /no_think prefix + Tier 3 JSON reinforcement + English enforcement
Magistral Standard prompt Suppressed [TOOL_CALLS] and [THINK] markers + ultra-strong JSON-only
GLM 4.7 Flash Verbose prompt Simplified + nested object fix + English enforcement
Nemotron 9B Full prompt /think prefix + simplified to 3 steps + Tier 3 JSON reinforcement

Supported Models

11 model families, 39+ model variants:

Family Models Key Adaptations
Claude Sonnet, Opus, Haiku XML tags, role extraction, Haiku simplification
OpenAI GPT-4o, o1, o3 Reasoning hints, grounding rules
Gemini Pro, Flash, Ultra Identity (baseline — no changes)
Qwen 235B, 32B, Coder Thinking mode, Tier 3 for 32B, English enforcement
DeepSeek V3, V3.1, V3.2 Self-verification, JSON reinforcement
Mistral Large, Magistral, Devstral, Ministral Marker suppression, type fixes, simplification
Llama 405B, 70B, 8B, 3B Grounding, small model simplification
Kimi K2, K2.5 Source grounding, English enforcement
GLM 4.7, 4.7 Flash Nested object fix, English, Flash simplification
Nemotron 30B, 12B, 9B Thinking mode, Tier 3 for small, simplification
MiniMax M2 Self-verification, contract-style

Task Types

Task When to Use
extraction Pulling structured data from documents
analysis Evaluating, comparing, or reasoning about data
generation Creating content, writing, summarizing
code Writing or reviewing code
general Everything else (default)

MCP Server

npm install -g @refrase/mcp-server

Add to your MCP config:

{
  "mcpServers": {
    "refrase": {
      "command": "refrase-mcp-server"
    }
  }
}

Adding New Model Adapters

See CONTRIBUTING.md for a 5-step guide to adding support for new models.

Research

Refrase's adaptation rules are derived from empirical testing across 46 model configurations on structured output tasks. Research paper coming soon.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

refrase-0.1.0.tar.gz (17.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

refrase-0.1.0-py3-none-any.whl (23.4 kB view details)

Uploaded Python 3

File details

Details for the file refrase-0.1.0.tar.gz.

File metadata

  • Download URL: refrase-0.1.0.tar.gz
  • Upload date:
  • Size: 17.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for refrase-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3f317fa57c608cc23c4f0a23db2111054cb92d34371a9e651a9f93c546fc3013
MD5 708336a32c754352d150a9fdb1fa67d5
BLAKE2b-256 53487a868deb898949c0e1d3df64a947ee7e3f6bb8ed407c6eae79612c3526c4

See more details on using hashes here.

File details

Details for the file refrase-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: refrase-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 23.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for refrase-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 85607c277ff10c8b0830da26bd3bbd6ef609690e9ad09cf866a3d60c8feec524
MD5 946aa564f5c944bab5a92abea902d298
BLAKE2b-256 441b79e98bd172ba97335e317c77fcfd97756bddd1063a8529728a8d482f7628

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page